473,396 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Regular Expressions and String Replacement

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
1 1249
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
3
by: Vibha Tripathi | last post by:
Hi Folks, I put a Regular Expression question on this list a couple days ago. I would like to rephrase my question as below: In the Python re.sub(regex, replacement, subject)...
7
by: Sally B. | last post by:
Hi, how would I go about doing the following: substitute all the strings 'the' and 'dog' in the 'mytext' id div only? The following doesn't work for 'the'. I also need to use regular expressions...
11
by: Dimitris Georgakopuolos | last post by:
Hello, I have a text file that I load up to a string. The text includes certain expression like {firstName} or {userName} that I want to match and then replace with a new expression. However,...
4
by: lucky | last post by:
hi there!! i'm looking for a code snipett wich help me to search some words into a particular string and replace with a perticular word. i got a huge data string in which searching traditional...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
0
by: peridian | last post by:
Hi, I wanted a web page where I could post code to, and have it appear in coloured formatting based on the context of the code. Most of the techniques I have seen for this involve complex use...
5
by: antar2 | last post by:
Hello, I am a beginner in Python and am not able to use a list element for regular expression, substitutions. list1 = list2 = Suppose that I want to substitute the vowels from list2 that...
2
by: Stimp | last post by:
Hi all, I'm having trouble trying to figure out the best approach to this problem and I believe regular expressions are the way to go. Basically I have created a large string of XHTML using a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.