<alert comment="regex and perl newbie">
I'm a C++ programmer using a regex library to do some
conversions of
html.
I've got input such as:
<p>The chair could be red or blue. It might be
green.</p>
I want to convert lines like the above to set up links so
the line
above becomes something like:
<p>The chair could be <a=0>red</a> or
<a=1>blue</a>. It might be
<a=2>green</a>.</p>
I could write three separate statements, such as:
Find: red
Substitute: <a=0>red</a>
Find: blue
Substitute: <a=1>blue</a>
Find: green
Substitute: <a=2>green</a>
Can this be done in one statement, so that the index of the
matched
alternative can be used as a variable:
Find: (red|blue|green)
Substitute: <a=#>$1</a>
In other words, can the regular expression library (such as
pcre or
greta or boost::regex) detect which of the alternatives was
actually
matched?
</alert>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regex googlegroups.com
To unsubscribe from this group, send email to
regex-unsubscribe googlegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---
|