Hi All, Here's a question I can't answer. I'm using regexp to dig out strings from data received via Ham Radio, so the txt often is corrupted. What I want to match is two consecutive callsigns separated by whitespace, for example 'hb9drv hb9drv' but not 'hb9drv hb9drX'. I can define the match condition for a callsign, but can I use the match option {2,3} somehow to match the same callsign two or three times? Effectively match the same word two or three times? Help received with much thanks, Simon Brown, Casa Bergenia, CH-7031 Laax www.hb9drv.ch [Non-text portions of this message have been removed]
On Monday, April 28, 2003, at 09:48 AM, Simon Brown wrote:
What I want to match is two consecutive callsigns separated by whitespace, for example 'hb9drv hb9drv' but not 'hb9drv hb9drX'.
I can define the match condition for a callsign, but can I use the match option {2,3} somehow to match the same callsign two or three times? Effectively match the same word two or three times?
You can do this with a back reference. This is documented at http://www.boost.org/libs/regex/syntax.htm. -- Darin
Here's a question I can't answer. I'm using regexp to dig out strings from data received via Ham Radio, so the txt often is corrupted.
What I want to match is two consecutive callsigns separated by whitespace, for example 'hb9drv hb9drv' but not 'hb9drv hb9drX'.
I can define the match condition for a callsign, but can I use the match option {2,3} somehow to match the same callsign two or three times? Effectively match the same word two or three times?
Help received with much thanks,
How about: (\w+)(?:\s+$1)+ John.
Hi John,
I think regexp is excellent, can even write some expressions (!) but this
one has me foxed, however I'll free up a brain cell or three and think it
through.
I'll also have a dig through the doc and see if it will do what I want - I
found (.*)\1 to behave slightly differently to what I expected, but that
could have been me. As this is for Amateur Radio (hobby) software I'll wait
until later this week, got to write some software for blind people tonight.
Simon Brown, Casa Bergenia, CH-7031 Laax
www.hb9drv.ch
----- Original Message -----
From: "John Maddock"
Which should of course have been: (\w+)(?:\s+\1)+
or "(\\w+)(?:\\s+\\1)+" if it's embedded in your program as a C string.
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? And a very, very big thanks to those who wrote regexp, you have no idea how useful it is for me :-) Simon Brown, Casa Bergenia, CH-7031 Laax www.hb9drv.ch
participants (3)
-
Darin Adler
-
John Maddock
-
Simon Brown