zeusdeux / re2

Automatically exported from code.google.com/p/re2
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

re2.h Replace function description incorrect #78

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
The re2.h header file's Replace() function description is incorrect. 
Backreferences are not supported, per documentation elsewhere on site. However, 
the description is nearly identical to the function of the same name in the 
pcre.h header file. 

1. Backrefs don't work:
std::string str = "testing1234regex"
RE2::Replace(&str, ".*(\\d+).*", "\1");
std::cout << "str='" << str << "' " << "\n";

What is the expected output? What do you see instead?
Expected: "1234"
Observed: " "

What version of the product are you using? On what operating system?
Build 20130115
OSX 10.7

Please provide any additional information below.
NOTE: If you have a suggested patch, please see
http://code.google.com/p/re2/wiki/Contribute
for information about sending it in for review.  Thanks.

Just wanting to get the description changed so someone like me doesn't get 
confused and frustrated by thinking backreferences really are supported.

Original issue reported on code.google.com by theperma...@gmail.com on 8 Apr 2013 at 5:29

GoogleCodeExporter commented 9 years ago
Above, I meant Apple's pcrecpp.h, not pcre.h
See http://opensource.apple.com/source/pcre/pcre-4.2/pcre/pcrecpp.h

Original comment by theperma...@gmail.com on 8 Apr 2013 at 5:32

GoogleCodeExporter commented 9 years ago
See note at bottom of https://code.google.com/p/re2/.  
Submatch references are fine in replacement strings.
I think the problem is that you've written \1 but need to write \\1 to get past 
the C string conventions.
Sorry for the long delayed reply.

Original comment by rsc@golang.org on 10 Jan 2014 at 3:22