Boost logo

Boost Users :

From: Ben Hutchings (ben.hutchings_at_[hidden])
Date: 2003-05-01 09:23:41


Simon Brown <simon.brown_at_[hidden]> wrote:
> 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.)


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net