boost::regex_search matching extra characters?

A

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 ")"
}

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?
 
T

Thomas J. Gritzan

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);
 
A

A

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,006
Latest member
LauraSkx64

Latest Threads

Top