473,406 Members | 2,620 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,406 software developers and data experts.

Boost RegEx

In my application I get a string from my datasource that I need to replace some of the bad chars in the strings.

Right now I have written a pretty standard regex that should replace any of the bad chars in the strings. However, instead of removing the bad chars it removes all chars from the string.

The bad chars I am trying to replace are /'()

Here is the current code that I am testing with.

Expand|Select|Wrap|Line Numbers
  1. boost::regex const string_matcher("/'()//gi");
  2. dataStr = boost::regex_match(results->GetString(column),string_matcher);
  3. cout << dataStr << endl;
  4.  
Dec 16 '08 #1
3 4504
Frinavale
9,735 Expert Mod 8TB
The algorithm regex_match determines whether a given regular expression matches all of a given character sequence denoted by a pair of bidirectional-iterators.

You want to replace characters so why are you using regex_match?
Why aren't you using the regex_replace method?
Dec 16 '08 #2
I do believe I read the api wrong then.

However, I still have an issue with this.

When i use the pattern below, I do not get the desired result of replacing . with _ and ' with \. Using the code below does not replace any of the bad chars.

If I have the string ROOM.width and I want to replace . with _, what would the syntax be for my regex.

Currently this is the code that I am testing with.

Expand|Select|Wrap|Line Numbers
  1. boost::regex const pattern("//'.()/gi", boost::regex_constants::icase|boost::regex_constants::perl);
  2. string replace("_");
  3. cout << boost::regex_replace (column, pattern, replace) << endl;
  4.  
Dec 16 '08 #3
Frinavale
9,735 Expert Mod 8TB
Some of the characters you are attempting to locate are regex syntax.

Please look into how to create regex expressions. One of my favorite resources on the topic is this site.

Your regex should look something like:

[\.\'\(\)]


Please take a look at the resource that I linked you to to understand how I came up with the expression.

A great place to check your regexs is this site.

-Frinny
Dec 16 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: sbobrows | last post by:
{Whilst I think much of this is OT for this newsgroup, I think the issue of understanding diagnostics just about gets under the door. -mod} Hi, I'm a C++ newbie trying to use the Boost regex...
2
by: Richard Latter | last post by:
Hello All, I am a newbie to the Boost library and I have a question about a simple function. All I would like to do is to create a simple function that can test strings using regular...
7
by: derek.google | last post by:
I hope a Boost question is not too off-topic here. It seems that upgrading to Boost 1.33 broke some old regex code that used to work. I have reduced the problem to this simple example: cout <<...
5
by: FBergemann | last post by:
I use SunOS 5.8, gcc 3.3.2, boost 1.33.1. I have build the entire boost package and try to compile a simple example: #include <iostream> #include <string> #include <boost/regex.hpp //...
4
by: DSmith1974 | last post by:
Are lookarounds supported in the boost regex lib? In my VS6 project using boost 1.32.0 I can declare a regex as.. <code_snippet> std::wstring wstrFilename = L"01_BAR08"; boost::wregex...
1
by: Yahooooooooo | last post by:
Just practicing BOOST regular expressions....giving errors... -- wanted to replace SPACE with NULL. #include <iostream> #include <fstream> #include <sstream> #include <string> #include...
3
by: MCH | last post by:
hi there, I am working with a HTML-like text with boost:regex. For example, the following pattern might occur in my text <abc efg> <p>EFG</p 12<3> In this case, I would like to extract...
3
by: neino | last post by:
Hello, did anyone of You have problems using boost::regex ? That code below : #include "boost/regex.hpp" /*1*/ int main() /*2*/ { /*3*/...
2
by: kvnil | last post by:
Could someone please explain what will happen with boost (and tr1) once c++09 is out. Take regex for example. There would (probably) be a regex support in c++09. 1) Does that mean I would be...
13
by: brad | last post by:
Still learning C++. I'm writing some regex using boost. It works great. Only thing is... this code seems slow to me compared to equivelent Perl and Python. I'm sure I'm doing something incorrect....
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.