Boost logo

Boost :

From: Thaddeus L. Olczyk (olczyk_at_[hidden])
Date: 2003-05-06 07:53:36

On Mon, 05 May 2003 22:18:57 -0400, Edward Diener
<eddielee_at_[hidden]> wrote:

>Thaddeus L. Olczyk wrote:
>> On Mon, 05 May 2003 18:47:15 -0400, Edward Diener
>> <eddielee_at_[hidden]> wrote:
>>> Use regex_grep to find matches and then regex_format in the Predicate
>>> function to change each match to another value.
>> Excuse me, but I see no place in the documentation where it describes
>> a format string which says something like " take all of the string
>> sans subexpression and set the subexpressions to xxxx".
>> Without that type of format string I do not see any way that
>> regex_format can do that.
>OK, I see now what you are trying to do. What about running a second
>regex_grep, after finding your initial match for the entire string in which
>you are searching, in which your regex string is:
>Then when a match is found in your regex_grep, use regex_format to change to
>the appropriate substitution by testing, in the regex_grep predicate
>function, for which one of the matches has been found.
>>> Thaddeus L. Olczyk wrote:
>>>> I've been searching the documentation for way to do regular
>>>> expression substitition of groups.
>>>> For example: Given the regex;
>>>> "My[ ]+name[ ]+is[ ]+($NAME)[.]+
>>>> I[ ]+live[ ]+at[ ]+($ADDRESS)[.]+
>>>> My[ ]+email[ ]+address[ ]+is[ ]+($EMAIL)"
>>>> I search some string for a match, find this:
>>>> "My name is $NAME . I live at $ADDRESS.
>>>> I am an acountant. My email address is $EMAIL"
>>>> and want to substitute
>>>> "Bob Smith" for $NAME
>>>> "1600 Pensylvania Ave." for $ADDRESS
>>>> "bob_at_[hidden]" for $EMAIL.

No. That won't work. You need to pin down
Unfortunately it is hard to find a realistic conterexample
for this simple example, but try.
"My name is $NAME . My wife's name is $NAME .
  I live at $ADDRESS. She lives at $ADDRESS.
  My email address is $EMAIL. Her email address is $EMAIL. "

With the regex
"name[ ]+is[ ]+($NAME)[.]+[ ]+live[s]?[ ]+at[ ]+($ADDRESS)[.]+
  [ ]+email[ ]+address[ ]+is[ ]+($EMAIL)"
Since it will result multiple substitutions for $NAME.

That being said, I posted the example because the language of regex's
can at times be ambiguous. It's better to answer the original question
rather than focus on the example.

Thaddeus L. Olczyk
Think twice, code once.

Boost list run by bdawes at, gregod at, cpdaniel at, john at