You can refer to text captured earlier in a pattern with a backreference: \1 refers to the contents of the first subpattern, \2 refers to the second, and so on. If you nest sub patterns, the first begins with the first opening parenthesis, the second begins with the second opening parenthesis, and so on .

For instance, this identifies doubled words:

preg_match('/([[:alpha:]]+)\s+\1/', 'Paris in the the spring', $m);
// returns true and $m[1] is 'the'