By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,849 Members | 2,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,849 IT Pros & Developers. It's quick & easy.

Regular Expressions and String Replacement

P: n/a
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."
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
a_*****@hotpop.com writes:
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

--
Frank Schmitt
4SC AG phone: +49 89 700763-0
e-mail: frankNO DOT SPAMschmitt AT 4sc DOT com
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.