For example:
$s1 = \"Test Test the rest of string\" $s2 = \"Test the rest of string\"
I would like to match positively $s1 but
$s1
~^(\w+)\s+\1(?:\W|$)~ ~^(\pL+)\s+\1(?:\PL|$)~u // unicode variant
\1 is a back reference to the first capturing group.
\1