php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1683 Failing to parse/compile a *? pattern.
Submitted: 1999-07-08 22:24 UTC Modified: 1999-07-08 22:44 UTC
From: roy at idle dot com Assigned:
Status: Closed Package: Parser error
PHP Version: 3.0.11 OS: Linux redhat 5
Private report: No CVE-ID: None
 [1999-07-08 22:24 UTC] roy at idle dot com
I have this line I'm trying to fix:

$body=eregi_replace("&lt;([^:]*://[^ >\n\t]*)&gt;", "<a href=\"\\1\">\\1</a>", $body);

My problem here is the regexp is greedy, so everything between one &lt; and the last &gt; are being seen as a single match. I wanted to fix the code with:

$body=eregi_replace("&lt;([^:]*://[^ >\n\t]*?)&gt;", "<a href=\"\\1\">\\1</a>", $body);

This adds a question mark after the second * wildcard. In theory this might make the * match be non-greedy, so it'd match off the first &gt; and not the last. But I get an error message:

Warning: REG_BADRPT in /home/roy/public_html/phorum/post.php3 on line 183

is this really an illegal regexp? From reading the regexp docs it seems adding a ? after any * should be valid. I also tried putting the ? outside the (), which compiles, but it still matche greedily.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-07-08 22:44 UTC] jim at cvs dot php dot net
The ereg_* functions don't support the non-greedy extensions.
Take a look at the preg_* functions (http://www.php.net/manual/ref.pcre.php3).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 09:01:27 2024 UTC