in reply to What does this code mean(Reg Exp)?
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.
|
|---|