Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > boost::regex_search matching extra characters?

Reply
Thread Tools

boost::regex_search matching extra characters?

 
 
A
Guest
Posts: n/a
 
      08-27-2010
I probably missed something stupid but why is this matching extra
characters?

if (boost::regex_search("bla bla (message #12345)",
matches,
boost::regex("\\(message #([0-9]+)\\)$")))
{
//matches[1].first contains "12345)" but regex is supposed to match only
"12345"
//matches[1].second contains ")"
}

I've tested regex in php so the regex should not match those extra chars
AFAIK

I solved this by removing the length of matches[1].second from first string
but is there something wrong with the above code or this is simply how
boost::regex works?


 
Reply With Quote
 
 
 
 
Thomas J. Gritzan
Guest
Posts: n/a
 
      08-27-2010
Am 27.08.2010 22:21, schrieb A:
> I probably missed something stupid but why is this matching extra
> characters?
>
> if (boost::regex_search("bla bla (message #12345)",
> matches,
> boost::regex("\\(message #([0-9]+)\\)$")))
> {
> //matches[1].first contains "12345)" but regex is supposed to match only
> "12345"
> //matches[1].second contains ")"
> }


Do you know what first and second are supposed to represent here?

first is the start of the matching sequence, second is one-past the
matching sequence.
This means that first and second are the same as begin() and end() of
all the C++ containers.

To extract the matching string, you can do:

std::string match(matches[1].first, matches[1].second);

--
Thomas
 
Reply With Quote
 
 
 
 
A
Guest
Posts: n/a
 
      08-28-2010
> first is the start of the matching sequence, second is one-past the
> matching sequence.
> This means that first and second are the same as begin() and end() of
> all the C++ containers.


well, i'm also into php where this is interpreted a little bit different and
where matches are usually what they are supposed to be - matches, so mixing
2 languages can get sometimes a bit confusing.

thank you for the explanation.


 
Reply With Quote
 
Francesco S. Carta
Guest
Posts: n/a
 
      08-28-2010
A <(E-Mail Removed)>, on 28/08/2010 05:21:49, wrote:

>> first is the start of the matching sequence, second is one-past the
>> matching sequence.
>> This means that first and second are the same as begin() and end() of
>> all the C++ containers.

>
> well, i'm also into php where this is interpreted a little bit different and
> where matches are usually what they are supposed to be - matches


Well, why, are they anything different?

The difference resides in how they are reported, and this information
usually is where it is supposed to be - in the documentation

http://www.boost.org/doc/libs/1_44_0...ex_search.html

--
FSC - http://userscripts.org/scripts/show/59948
http://fscode.altervista.org - http://sardinias.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does return-by-value mean extra copies and extra overhead? mathieu C++ 3 09-04-2009 04:25 PM
Help with Pattern matching. Matching multiple lines from while reading from a file. Bobby Chamness Perl Misc 2 05-03-2007 06:02 PM
wireless question - extra gateway =?Utf-8?B?Uks=?= Wireless Networking 0 07-24-2004 08:14 PM
Matching strings with index &#8211; getting extra matches. G Perl Misc 7 02-12-2004 06:15 PM
Pattern matching : not matching problem Marc Bissonnette Perl Misc 9 01-13-2004 05:52 PM



Advertisments