Modify

Ticket #589 (closed Bugs: fixed)

Opened 8 years ago

Last modified 22 months ago

regex_replace bug

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

Description (last modified by johnmaddock) (diff)

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

Change History

comment:1 Changed 8 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 8 years ago by johnmaddock

  • Status changed from assigned to closed

comment:3 Changed 2 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 2 years ago by coffman@…

  • Status changed from closed to reopened
  • Resolution Invalid deleted

comment:5 Changed 22 months ago by johnmaddock

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

(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 22 months 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 22 months ago by johnmaddock

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

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
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.