开发者

Check if two parts of a string are the same with regex (PHP)?

开发者 https://www.devze.com 2023-01-15 08:06 出处:网络
using a regular expression in PHP with preg_replace_callback how can I check if two parts of the pattern are the same?

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 (.+?), (**Strin开发者_Go百科g Here Must Be Same as First Match**)/s', create_function(), $subject);

Thanks, Matt


You can use a backreference:

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

\1 here denotes the first matched group.

0

精彩评论

暂无评论...
验证码 换一张
取 消