1 May
2003
1 May
'03
2:23 p.m.
Simon Brown
A few days ago I received great help with a regexp question - now here's another which I doubt can be done.
Question: if the text string contains three words AAA BBB AAA then return the string (if any) which is repeated two or three times.
Examples: AAA AAA AAA return AAA AAA BBB AAA return AAA AAA AAA BBB return AAA AAA BBB CCC return <nothing>
Can this be done with a regular expression?
Match against "(\\w+) (?:\\1 \\w+|\\w+ \\1)|\\w+ (\\w+) \\2" and return the match for whichever sub-expression (1 or 2) was matched. (I tested this with Python not Boost regex, but they should be compatible.)