|
Boost Users : |
From: Duane Murphy (duanemurphy_at_[hidden])
Date: 2002-05-31 18:54:25
--- At Fri, 31 May 2002 15:04:04 -0700, Duane Murphy wrote:
>Fellow Boosters,
>I am looking for a little guidance with the regex library. I have an
>application that I would like to use regex for. I am new to regex so I am
>not sure how to approach it. Mostly I am reading. The examples so far
>have been very impressive, but so complicated as to make it difficult to
>understand how to do something simple.
>
>What I would like to do is process a string (or file) that has many
>symbols that are delimited with something like "&foo;". The delimiters
>are not that interesting. Just something to make them easy to locate. The
>string between the delimiters is then used to lookup a replacement string
>and substituted. I would search for something like "&.*;".
>
>The examples show how a basic search and replace would work, but how
>would I do something with a looked-up replace?
Let's see if I can answer my own question. :-)
Looking at the implementation of regex_merge gives the answer.
regex_merge uses regex_grep and a predicate function object to do the
work. By tracking the iterator position from the previous match to the
next match, all characters that dont match can be sent to the output
iterator. The found expresion can be evaluated and then searcing can
continue. Finally a little cleanup at the end to emit the last bit of
text that has no matches in it.
This seems like it might work. Basically regex_merge with symbol lookup
rather than a replace format.
...Duane
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