473,382 Members | 1,365 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,382 software developers and data experts.

Does boost::regex_search support branch sentence like (....)|(....)?

#include <iostream>
#include <string>
#include <boost/regex.hpp>
using namespace std;

int main(int argc, char* argv[])
{
string inStr =
"123456"
"abcde"
"1-2";
std::string regstr =
"(\\d+)|"
"(a-z)";
boost::regex _reg(regstr);
boost::smatch what;
std::string::const_iterator _start = inStr.begin();
std::string::const_iterator _end = inStr.end();
while (boost::regex_search(_start, _end, what, _reg))
{
std::string msg1(what[1].first, what[1].second);
cout << msg1.c_str() << endl;
_start = what[1].second;
}
return 0;
}

run result:
123456
1
2

why can't find "abcde"?
Jun 27 '08 #1
4 1261
On Sat, 10 May 2008 19:37:47 -0700 (PDT) in comp.lang.c++, ????
<ke****@gmail.comwrote,
std::string regstr =
"(\\d+)|"
"(a-z)";
>why can't find "abcde"?
Because it doesn't have a '-' or a 'z' in it after the 'a'.
Jun 27 '08 #2
In article <46fdda6b-39ad-444b-87b9-
02**********@k1g2000prb.googlegroups.com>, ke****@gmail.com says...

[ ... ]
"(a-z)";
[ ... ]
why can't find "abcde"?
My guess is that you intended to use "[a-z]" instead...

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jun 27 '08 #3
In article <MP************************@news.sunsite.dk>,
jc*****@taeus.com says...
In article <46fdda6b-39ad-444b-87b9-
02**********@k1g2000prb.googlegroups.com>, ke****@gmail.com says...

[ ... ]
"(a-z)";

[ ... ]
why can't find "abcde"?

My guess is that you intended to use "[a-z]" instead...
Oops -- to match 'abcde' it'd need to be something like "[a-z]+" -- by
itself, [a-z] only matches a single lower-case letter. To match more
than one, you need to append something like '+' or '*'.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jun 27 '08 #4
On 2008-05-11 04:37, 凯ä¸* wrote:
#include <iostream>
#include <string>
#include <boost/regex.hpp>
using namespace std;

int main(int argc, char* argv[])
{
string inStr =
"123456"
"abcde"
"1-2";
std::string regstr =
"(\\d+)|"
"(a-z)";
I think you intended to find a string consisting of either one or more
numbers or one or more lower-case letters. While I'm not familiar with
the Boost::regex dialect the above probably means one or more numbers
followed by a "|" followed by an "a", a "-", and a "z". You probably
want something like this:

((\\d+)|([a-z]+))

Notice that this introduces a new capturing group, there should be a way
to make the added pair of parenthesis non-capturing, probably something
like:

(?:(\\d+)|([a-z]+))

--
Erik Wikström
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hon Seng Phuah | last post by:
Hi, I am quite new to perl development and have a question very stupid question. I hope that someone can help me. Does perl support in/out parameter subroutine? Like in C/C++, we have a...
10
by: Bill Davidson | last post by:
Hi there, Please forgive me for posting this article on multiple groups. Being new in the newsgroups, I was not sure which group would have been appropriate for my question. Sorry. My...
8
by: David Bray | last post by:
I have an Access database on an ISP's web-space which is accessed through ASP - all standard stuff. Can anyone tell me whether ASP's object.context methods for transactions will work with...
10
by: Buck Rogers | last post by:
Hi guys! Does anyone have a link to a site that provides up to date programming book reviews? I looked through the reviews at: http://www.accu.org/bookreviews/public/index.htm ...
4
by: Molina | last post by:
Hi !!! I have a VB.Net application that consumes an WebService. The problem is that the HTTP address works fine, but it will change to an HTTPS address, and it isn't working. The weird thing...
5
by: Chris Sharman | last post by:
Anyone know a good, current reference ? I found Meyer's table (now moved to http://www.ddj.com/webreview/style/css1/charts/mastergrid.shtml ) and it's 5 years since the last update. Most other...
8
by: Divick | last post by:
Hi all, can somebody tell how much std::wstring is supported across different compilers on different platforms? AFAIK std::string is supported by almost all C++ compilers and almost all platforms,...
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...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: 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...

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.