-
October 23rd, 2006, 09:43 PM
#1
perl regular expession
How do I have my php match the following:
"<key1></key1>" but not "<key1></key2>"
Basically I have the following:
"<key1>Something inside here</key1><key2>Something inside here</key2>", and so my preg looks like this:
Code:
if ( !preg_match("/(<key\d+>.*?<\/key\d+>|)+/,$variable) )
{
$error = true;
}
But it would be cool to check to see if its incremented like 1...2...3 and to see if they are the same.
-
October 24th, 2006, 02:41 PM
#2
Re: perl regular expession
I'm not sure about PHP but in Perl you'd use backreferences. For example, you can do something like:
/(<(key\d+)>.*?<\/$2>|)+/
In other words, you're creating a second capture group around the around the key entry and looking for the output of that same capture group in an adjacent tag.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|