Modify

Opened 11 years ago

Closed 5 years ago

Last modified 5 years ago

#589 closed Bugs (fixed)

regex_replace bug

Reported by: nobody Owned by: johnmaddock
Milestone: Component: regex
Version: None Severity: Problem
Keywords: Cc:

Description (last modified by johnmaddock)

boost::tregex e("(.*)");
strResult = boost::regex_replace("a", e, "$1b");

strResult now equals "abb", but should be "ab".

My e-mail: kdn01003@student.mdh.se

Attachments (0)

Change History (7)

comment:1 Changed 11 years ago by johnmaddock

Logged In: YES 
user_id=14804

This is by design, and is compatible with the way Perl does
things: two matches are found, the first matches the "a",
the second matches the zero length string immediately after
the "a".  Therefore two replacements are performed, and
hense the output.  Use .+ instead of .* if you don't want to
find zero length matches.

John Maddock

comment:2 Changed 11 years ago by johnmaddock

  • Status changed from assigned to closed

comment:3 Changed 6 years ago by coffman@…

  • Severity set to Problem

I have found this behavior still exists even when using posix basic or extended regexes. While this behavior may be correct for perl regexes it doesn't seem to be correct for posix basic or extended regexes.

std::string s("a"); const boost::regex e("(.*)", boost::regex::extended); std::string result = boost::regex_replace(s, e, "$&b");

The result is "abb"

If I use gnu's sed utility (GNU sed version 4.1.2) instead I get "ab"

echo a | sed -r "s/(.*)/\1b/g"

and gnu's sed utility claims to use posix extended regex expressions when called with the -r option.

comment:4 Changed 6 years ago by coffman@…

  • Resolution Invalid deleted
  • Status changed from closed to reopened

comment:5 Changed 5 years ago by johnmaddock

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [79339]) Fix regex_iterator and regex_replace to do what grep/sed do for multiple repeats when matching in POSIX mode. Fixes #589.

comment:6 Changed 5 years ago by johnmaddock

  • Description modified (diff)

This is now fixed in Trunk provided match_posix is passed to regex_replace or regex_iterator.

comment:7 Changed 5 years ago by johnmaddock

(In [79556]) Merge collected bug fixes from Trunk: Refs #589. Refs #7032. Refs #7084. Refs #6346.

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain johnmaddock.
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.