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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: roy at idle dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Sat Jan 04 22:01:28 2025 UTC