|
Boost Users : |
From: John Maddock (john_maddock_at_[hidden])
Date: 2003-05-29 06:10:09
> I have a string that I'm searching, with sub-fields that are delimited
> by '~'. I'm particularly interested in 2 of the fields, either of which
> may or may not exist, in an unspecified order, and are identified by an
> initial 'C' and 'O' respectively. The 'C' is always followed by one or
> more digits, the 'O' is followed by one or more characters.
>
> For example, these are all valid.
>
> ~A123~C456~MA4
> ~C12345~OA1~A123
> ~A4~MH1
>
> I'd like to see if I can use regular expressions to say, "If there is a
> 'C' field, replace the digits after it with these digits. If there is
> an 'O' field, replace the characters after it with these characters."
>
> I can do this quite easily with two different regex search-and-replaces;
> if the fields were always in the same order, I'd have no problem with
> that, either. Is it possible to do this in a single operation, given
> that the order of the fields is arbitrary?
Yes do a conditional search and replace:
search for "C(\\d+)|O(\\w+)"
and replace with "(?1first-text)(?2second-text)"
don't forget to set the flag format_all when calling regex_merge to do this
(in future conditional replacements will only be enabled when actually
requested).
John.
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