|
Boost : |
From: John Maddock (jm_at_[hidden])
Date: 2003-05-07 05:49:46
> 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.
>
> I have not been able to find a method that will do this for me.
Try the regex:
"(My[ ]+name[ ]+is[ ]+)($NAME)([.]+I[ ]+live[ ]+at[ ]+)($ADDRESS)([.]+My[ ]+
email[ ]+address[ ]+is[ ]+)($EMAIL)"
And replace with (using regex_merge):
"$1Bob Smith$31600 Pensylvania Ave.$5bob_at_[hidden]"
Alternatively, how about searching for:
($NAME)|($ADDRESS)|($EMAIL)
and replacing with:
(?1Bob Smith)(?231600 Pensylvania Ave.)(?3bob_at_[hidden])
John.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk