Firstly, as mentioned elsewhere, you should probably use str_replace() rather than regex for simple cases like the one in your example.
Now, a quick explaination about regex in PHP:
As you clearly already know, the ereg_* functions are now deprecated in PHP, and you should use the preg_* functions instead.
The main difference between the two sets of functions is the type of regular expression that they use. The ereg functions use POSIX-style regex, while the preg functions use PERL-style regex. The PHP developers have decided to standardise on PERL-style regex, hence why the ereg functions are being deprecated.
I mention all this because it is helpful to understand the differences between the two types of regex when converting from one to the other.
For the most part, they are actually very similar - most common regex codes work the same between them both. For example, the ^
and $
are the same in both, denoting anchors to the begining and end of the string.
Where they differ in a big way is that the preg functions do not support the wordy character classes that ereg supports. So if you have any eregs that include codes like [:digit:]
or [:alpha:]
then you'll have more work to convert them. They can still be converted, though.
There are a few other differences between the two, but unless you're doing complex expressions (and it doesn't sound like it), you're unlikely to run into any other problems converting between the two styles.
Other than that, the one big difference is that preg requires a delimiter character at either end of the regex string to denote that it's a regex. (this is usually a slash, but can be almost any symbol as long as it's the same at both ends). This is not the same as the ^ and $, though, so your remark about replacing them is incorrect; you still need the ^ and $ as well as the slashes.
Therefore: to convert ereg code like this: '^xyz$'
, you would just add slashes, like so: '/^xyz$/'
Hope that helps.
[edit]
Just a quick edit to give you some additional reference material:
Both of those are in my permanent bookmarks.