1

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

1 Answer 1

4

You can use a backreference:

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

\1 here denotes the first matched group.

Sign up to request clarification or add additional context in comments.

5 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.