Re: Regexp Oddity
| From: | Raditha Dissanayake | Date: | Thu, 11 Mar 2004 06:50:16 +0000 |
| Subject: | Re: Regexp Oddity | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-180105@lists.php.net to get a copy of this message | ||
print "Matches: " . preg_match('/((?i)rah)\s+\1/', "RAH RAH") . "\n";
print "Matches: " . preg_match('/((?i)rah)\s+\1/', "rah rah") .
is what you should use.
trlists@clayst.com wrote:
I must be missing something obvious ... I am trying to use backreferences in a PCRE regexp to check for a repeated character, but they don't seem to work. I've used regexps often before, but never needed backreferences. For example this: print "Matches: " . preg_match("/(a)\1/", "aa"); prints: Matches: 0 It should be 1. In addition the basic examples in the manual fail. The manual says: For example, ((?i)rah)\s+\1 matches "rah rah" and "RAH RAH", but not "RAH rah", even though the original capturing subpattern is matched caselessly. I tested this with: print "Matches: " . preg_match("/((?i)rah)\s+\1/", "RAH RAH") . "\n"; print "Matches: " . preg_match("/((?i)rah)\s+\1/", "rah rah") . "\n"; Both show 0. For this test I'm running PHP 4.3.1 on Windows 2000. What am I missing? -- Tom-- Raditha Dissanayake. --------------------------------------------------------------- http://www.radinks.com/upload/ Drag and Drop Upload thousands of files and folders in a single transfer. (HTTP or FTP)