Regular Expressins TR1
Apr 11, 2012 at 6:18am UTC
Hi, I need advice. I have simple artifical example.
1 2 3 4 5 6
#include <regex>
const std::string sStdPattern = "(A)(B)(B)(B)(B)(B)(B)(B)(B)(B)(B)(B)(B)(B)(B)" ;
const std::string sStdReplacement = "$11" ;
const std::string sStdText = "ABBBBBBBBBBBBBB" ;
const std::tr1::regex rx(sStdPattern);
const std::string sStdResult = std::tr1::regex_replace(sStdText, rx, sStdReplacement);
I need output "A1" - Letter "A" from first group (A) and number one "1". But code returns 11th group (B) = so output is "B".
ECMA syntax doesn't support "${1}1".
Any suggestions?
Thx. Frank
Apr 11, 2012 at 5:15pm UTC
You can do this:
1 2 3 4 5 6 7
const std::string sStdPattern = "(A)(B)(B)(B)(B)(B)(B)(B)(B)(B)(B)(B)(B)(B)(B)" ;
const std::string sStdReplacement = "$1" ;
const std::string sStdText = "ABBBBBBBBBBBBBB" ;
const std::tr1::regex rx(sStdPattern);
std::string sStdResult = std::tr1::regex_replace(sStdText, rx, sStdReplacement);
sStdResult += "1" ;
std::cout << sStdResult << std::endl;
Apr 15, 2012 at 4:52am UTC
Yes, I can. Thx.
But this is not answer for my question.
You suggest "c++ syntax solution". I try to find "regular expression (ECMA) syntax solution".
Apr 15, 2012 at 7:03am UTC
Then maybe ECMA engine is not appropiate for you. I used PCRE (Perl Compatible Regular Expression) library in the past with great results and it is cross-platform. Look at it for a replacement.
Topic archived. No new replies allowed.