Regular Expressions and String Replacement

A

a_the_s

Forethought: I'm using FreeBSD 5.1, gcc 3.2.1
The program takes a string (completely unaware of its contents), parses out HTML, then sends it on its way.

Simply put - is there an {easy} way to evaluate a regular expression on a string, read the results, then replace each of the results?

Technically put...
What I'm trying to do is easily accomplished in perl with something like..
$string_var = s/PATTERN/REPLACEMENT/{flags};
Those used to sed will recognize the s/// format. Unfortunately, I'm not using perl for this program.
My first attempt at solving the problem was using regex() and regcomp(). Unfortunately, I wasn't able to find a function to replace the substrings for me (yes, it seems lazy).
Then, looking back on the perl example, I figured I'd -sed- it. This works just fine, but, since the program won't know what's in the string, running a system command with the string in it may cause a security leak. Sooooo..that runs in to a bunch of garbage with piping.

ick.

The program works fine now, with the second example of piping to sed. But there has to be an easier way. Thanks for input!

-Elliot :)

--
"Serpent!" screamed the Pigeon.
"I'm not a serpent!" said Alice indignantly. "Let me alone!"
"Serpent, I say again!" repeated the Pigeon, but in a more subdued tone, and added with a kind of sob, "I've tried every way, and nothing seems to suit them!"
- L. Carroll
-==++==++==++==++==++==-
"Always the hours."


--
"Serpent!" screamed the Pigeon.
"I'm not a serpent!" said Alice indignantly. "Let me alone!"
"Serpent, I say again!" repeated the Pigeon, but in a more subdued tone, and added with a kind of sob, "I've tried every way, and nothing seems to suit them!"
- L. Carroll
-==++==++==++==++==++==-
"Always the hours."
 
F

Frank Schmitt

Forethought: I'm using FreeBSD 5.1, gcc 3.2.1
The program takes a string (completely unaware of its contents),
parses out HTML, then sends it on its way.

Simply put - is there an {easy} way to evaluate a regular expression
on a string, read the results, then replace each of the results?

You should take a look at the boost regex library -
you can find it at www.boost.org.

HTH & kind regards
frank
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top