ID: 34530 Updated by: [EMAIL PROTECTED] Reported By: php at clayst dot com -Status: Open +Status: Bogus Bug Type: PCRE related Operating System: Windows XP Pro PHP Version: 4.4.0 New Comment:
Thank you for not searching the bug database before submitting yet another bogus bug report about this issue. Read about the limitations in PCRE library here: http://www.pcre.org/pcre.txt This is not PHP bug, just PCRE library's limitation. (also mentioned in the manual, if you had bothered reading it) Previous Comments: ------------------------------------------------------------------------ [2005-09-16 19:27:39] php at clayst dot com Description: ------------ A regular expression which involves some unnecessary extra loops in execution will give the proper result (a match) with a given input string but will fail to match when it should if the input is one character longer. In the example, the pattern is intended to match a string which contains: (1) An optional substring consisting of one or more groups of word characters separated by dashes, with the entire substring (if present) terminated by a period; followed by (2) A required substring consisting of one or more groups of word characters separated by dashes. The 'good' pattern shown does this properly. The 'bad' pattern incorrectly makes the dashes between substrings optional -- i.e. there's an extra '?" after the '-' in both portions of the pattern. This error makes the pattern inefficient as there are many possible matching substrings, but I believe it should still match a simple alpha string. In fact it fails to match if the input string is more than 20 characters long. Reproduce code: --------------- <?php $goodpattern = '/^((\w+(-\w+)*)\.)?(\w+(-\w+)*)$/'; $badpattern = '/^((\w+(-?\w+)*)\.)?(\w+(-?\w+)*)$/'; $string1 = str_repeat('a', 20); $string2 = str_repeat('a', 21); print('Good pattern, 20 characters: ' . preg_match($goodpattern, $string1) . "\n"); print('Good pattern, 21 characters: ' . preg_match($goodpattern, $string2) . "\n"); print('Bad pattern, 20 characters: ' . preg_match($badpattern, $string1) . "\n"); print('Bad pattern, 21 characters: ' . preg_match($badpattern, $string2) . "\n"); ?> Expected result: ---------------- All matches should return a 1 because they all match the given string. Actual result: -------------- The first three matches return a 1 but the last returns a 0: Good pattern, 20 characters: 1 Good pattern, 21 characters: 1 Bad pattern, 20 characters: 1 Bad pattern, 21 characters: 0 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=34530&edit=1