Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#2165 closed Bugs (invalid)

regex_search match but regex_match is not filled

Reported by: mickael@… Owned by: John Maddock
Milestone: Boost 1.36.0 Component: regex
Version: Boost 1.35.0 Severity: Problem
Keywords: regex_search regex_match Cc:

Description

Hi,

I face a problem with the regex_search function. If a piece of the subject match the pattern, and the matched string isn't at start of subject, then regex_search return true but the match_results is empty.

I attach a test case source.

Sorry for my english, I'm French ;)

Attachments (1)

regex-bug.cpp (1.7 KB ) - added by mickael@… 14 years ago.
Test case for the problem.

Download all attachments as: .zip

Change History (3)

by mickael@…, 14 years ago

Attachment: regex-bug.cpp added

Test case for the problem.

comment:1 by John Maddock, 14 years ago

Resolution: invalid
Status: newclosed

I believe this is a misunderstanding of how regular expressions work: if the expression is [a-z]* then it is perfectly legal to match a zero-length string if the * operator repeats zero times. So for example [a-z]* matched against the string " abc " can find 4 matches:

  • the zero length string at the start of the " abc ".
  • the string "abc".
  • the zero length string after the "c".
  • the zero length string at the end of " abc ".

When a zero length string is matched, then sub_match::first == sub_match::second and sub_matched::matched == true.

Probably you meant to use [a-z]+ as the regular expression?

If this doesn't clarify the issue, or if I've misunderstood, please reopen the ticket.

HTH & bonjour, John Maddock.

comment:2 by mickael@…, 14 years ago

Bonjour :)

You're right, I misused regex_search. I correct my code to increment the start iterator when first == end, and add a test start != end before regex_search.

Even Boost::regex stress me a lot, its approach is great.

Thanks for your fastness !

Note: See TracTickets for help on using tickets.