tags:

views:

22

answers:

1

Hi guys, using a regular expression in PHP with preg_replace_callback how can I check if two parts of the pattern are the same?

preg_replace_callback('/Blah: (.*?), BLah Blah (.+?), (**String Here Must Be Same as First Match**)/s', create_function(), $subject);

Thanks, Matt

+4  A: 

You can use a backreference:

/Blah: (.*?), BLah Blah (.+?), \1/s

\1 here denotes the first matched group.

casablanca
Best place to go for more information on them is http://www.regular-expressions.info/brackets.html
Jason Lewis
Thanks for posting the link, I thought of adding a reference myself. :)
casablanca
I was going to post an answer, but a comment reference will do. :)
Jason Lewis
Excellent! Thanks Guys! I've been trying to do this for the last 6 months lol!
Matt
You're welcome. Why did you wait 6 months to post in the first place? :)
casablanca