#49247 [NEW]: preg_match_all and \w issues

From: Date: Thu, 13 Aug 2009 23:16:35 +0000
Subject: #49247 [NEW]: preg_match_all and \w issues
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-141035@lists.php.net to get a copy of this message
From: mariusads at helpedia dot com Operating system: Windows 2003 Web Edition PHP version: 5.2.10 PHP Bug Type: PCRE related Bug description: preg_match_all and \w issues Description: ------------ I was under the impression that \w matches any word character, as in a-z, A-Z, 0-9 and _ characters (documentation also says "some character codes greater than 128 are used for accented letters, and these are matched by \w" if a specific code page is used but it's not the case here, it's a default PHP installation). However, I have noticed the following issue and I'm not sure if it's a bug in PHP or an error in the way I've written the regular expression in the code below. As I understood regular expressions work, the code below should not return any match but it does. Reproduce code: --------------- $text = 'start://abcd'.chr(255).chr(255).'efgh'; $results = preg_match_all('/(start:\/\/|finish:\/\/){1}([\w\x3A - \x40]*)$/is',$text,$matches,PREG_OFFSET_CAPTURE); var_dump($results,$matches); Expected result: ---------------- The could above should return no matches. If the $ at the end is omitted, I think it should return "start://abcd". Replacing \w with 0-9a-zA-Z_ produces the correct output. Actual result: -------------- Output of the above code: int(1) array(3) { [0]=> array(1) { [0]=> array(2) { [0]=> string(18) "start://abcd��efgh" [1]=> int(0) } } [1]=> array(1) { [0]=> array(2) { [0]=> string(8) "start://" [1]=> int(0) } } [2]=> array(1) { [0]=> array(2) { [0]=> string(10) "abcd��efgh" [1]=> int(8) } } } -- Edit bug report at http://bugs.php.net/?id=49247&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49247&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49247&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49247&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=49247&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49247&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=49247&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=49247&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=49247&r=needscript Try newer version: http://bugs.php.net/fix.php?id=49247&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=49247&r=support Expected behavior: http://bugs.php.net/fix.php?id=49247&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=49247&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=49247&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=49247&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49247&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=49247&r=dst IIS Stability: http://bugs.php.net/fix.php?id=49247&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=49247&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=49247&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=49247&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=49247&r=mysqlcfg

« previous php.bugs (#141035) next »