Replace ereg with preg_match

How to update to using preg_match on newer versions of PHP

I was recently developing on a newer version of PHP than what is currently used on most of our servers and I was getting a warning telling me that the function ereg was depreciated.

A little googling told me that is is going to be totally removed from PHP 6 so in the interest of keeping my code nice and up to date I made the following changes....

Use preg_match instead of ereg and wrap the expression with //


Here is an example;

ereg("^[-]?[0-9]+([\.][0-9]+)?$", $var);


preg_match("/^[-]?[0-9]+([\.][0-9]+)?$/", $var);

Recent posts View all


How to ignore Bullet in RSpec tests

Using Bullet during a test can pick up mistakes but also has false negatives; here is an easy way to ignore them


How we used Nokogiri to fix a sizing issue in YouTube's oEmbed

At some point, one of our calls to YouTube's oEmbed endpoint was returning videos way too small; we fixed in in our Rails application by using Nokogiri