Do you know what $1 is? Well, \1 is just the same but within a regex. Well, now, why don't you give a peek into perlre? | [reply] [d/l] [select] |
| [reply] |
Inside a regular expression, a construct of the form \NNN, that is, a backslash followed by one or more numbers, the first number not a zero, refers to the NNN'th set of parenthesis - that is, \1 matches exactly was matched by the first set of parenthesis.
So, in your example, the code is looking for a sequence of characters, delimited by word/non-word boundaries, which repeats itself with a single space separating the sequences. Note that there isn't a requirement that the second sequence terminates (or starts) at a word boundary. "cat cats" matches. To match consecutive words, I would use: /(\b\w+\b)\s+\b\1\b/ - unlike the regex you presented that requires the sequence of characters to consist of word characters, allows more than one space between consecutive words, and requires the second sequence to be a complete word as well. | [reply] [d/l] [select] |