October 9th, 2008, 03:49 AM
Regular Expressions are Eating Too Much
I am trying to get a relatively simple regular expression working. By default, regular expressions eat as much of the string as possible. In this case, however, I am trying to find the end of a link ("</a>"), so I want the regular expression to eat as little as possible. Normally, you can put a ? after the * to indicate that it should try for small matches, but PHP's eregi-replace is throwing me a REG_BADRPT error.
String is something like this...
"(<a .*</a>)" works, but eats too much
"(<a .*?</a>)" throws an error
October 9th, 2008, 03:57 AM
1) Post in the right forum
2) Use preg_replace
3) You want to find everything between <a and </a>? Including what's in the HTML?
4) Regular expressions are extremely obese, please do not make fun them, guys.
October 9th, 2008, 04:00 AM
Using ? as an ungreedy modifier is a Perl/PCRE feature. It doesn't work with the ereg* functions.
Quoted for emphasis.
Originally Posted by ryon420
Comments on this post
October 10th, 2008, 08:21 AM
I'm leaving this thread in the PHP forum since this appears to be less of a regular expression issue and more related to PHP functions.
Explain your problem instead of asking how to do what you decided was the solution.
October 10th, 2008, 08:41 AM
Since ereg_* functions are not binary safe, personally I am trying to avoid using them at all. Also the PHP manual states that PCRE are often faster. And I read somewhere POSIX regular expressions are going to to be moved to PECL in the future versions of PHP. I would advise not to use ereg_* functions if possible and use preg_* functions instead ...
Last edited by SKDevelopment; October 10th, 2008 at 08:44 AM.