Regexp Oddity
| From: | trlists at clayst dot com | Date: | Thu, 11 Mar 2004 04:32:28 +0000 |
| Subject: | Regexp Oddity | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-180099@lists.php.net to get a copy of this message | ||
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