[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

boost::regex_relace vs. std::regex_replace: Who is right?

boost::regex_relace vs. std::regex_replace: Who is right?

Ralf Goertz

6/14/2016 8:32:00 AM

Hi

after upgrading gcc from version 4.8.5 to version 5.3.1 I thought I
could get rid of boost's regex-implementation (boost version 1.54.0) and
use the one provided by gcc (it didn't work with gcc before version 4.9
AFAIK). However, this turned out to be a problem because those two
implementations behave differently:


#include <regex>
#include <boost/regex.hpp>
#include <iostream>
#include <string>

int main() {
std::string s="\\needs_another_backslash";
std::string reg("^\\\\");
std::string rep("\\\\");
std::regex sr(reg);
boost::regex br(reg);
std::cout<<"string before replacement:\n"<<s<<std::endl<<
"std::regex_replace:\n"<<std::regex_replace(s,sr,rep)<<std::endl<<
"boost::regex_replace:\n"<<boost::regex_replace(s,br,rep)<<std::endl;
return 0;
}

The output of that program is:

string before replacement:
\needs_another_backslash
std::regex_replace:
\\needs_another_backslash
boost::regex_replace:
\needs_another_backslash


It seems as if boost treats the '\' in a replacement string specially
whereas gcc does not. According to
http://www.cplusplus.com/reference/regex/rege... the magical
character for backreference etc. in the replacement string is '$'. So I
tend to think that gcc is right. However, in other programs (like vim
e.g.) it is '\'. So boost might have a point in treating '\' specially.
So who is right?

Ralf


Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
boost::regex_relace vs. std::regex_replace: Who is right?

Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te

Il servizio è completamente GRATUITO!