php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7222 ereg_replace, ereg
Submitted: 2000-10-15 11:46 UTC Modified: 2000-10-17 13:58 UTC
From: zibin at tx dot technion dot ac dot il Assigned:
Status: Closed Package: *Regular Expressions
PHP Version: 4.0.2 OS: unix
Private report: No CVE-ID: None
 [2000-10-15 11:46 UTC] zibin at tx dot technion dot ac dot il
everytime I have a regular expression which have ".*" or "[0-9]*" I get the following error:

Warning: REG_BADRPT in /home/websites/www.gigcenter.com/DB.htmlToPHP3.php3 on line 236

For example:
if ( eregi("onlyuser\[(.*?)\]",$inside, $regs) ||
				
if ( eregi("adduser\[(.*?)\]",$inside, $regs) ) {
				
But this doesn't cause error:
if ( eregi("authenticate=(.)",$inside, $regs) )
					$authenticate = $regs[1];

				if ( eregi("MUST Authenticate",$inside) )


thanks for your time.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-10-15 19:14 UTC] torben@php.net
I don't believe that this is a bug--those aren't valid POSIX regular
expressions. It looks like you're trying to use a perl-style non-greedy
operator (?) after the .* piece, which isn't part of the POSIX regex syntax.

For more information on POSIX regex syntax, check out the manual
page which comes with the PHP source--in PHP 4, it's located in
/path/to/php4/regex/regex.7. You can read it by doing something like:

% man /path/to/php4/regex/regex.7

If you want to use non-greedy type regexes, you should use the perl-
compatible functions; if you want to catch all of the instances found in a
string, use preg_match_all(). Something like this:

if (preg_match_all('/onlyuser\[(.*?)\]/i', $inside, $regs)) {
    var_dump($regs);
}

Check out http://www.php.net/manual/function.preg-match-all.php and the
manual entries on syntax and pattern modifiers for more information.

 [2000-10-16 15:30 UTC] joey@php.net
Actually, the problem is in the escaping of the [ and ].

The first \ is being eaten by the PHP parser.

What you really want is

eregi("onlyuser\\\[(.*?)\\\]",$inside, $regs)
 [2000-10-17 13:58 UTC] joey@php.net
My mistake. My comments are only true in php 3.0.x
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Dec 07 16:03:34 2021 UTC