boost::xpressive use of before(...)
Good morning, In our project I have the enviable task of transforming a large number of perl regex into boost::xpressive static code in c++. To ensure that the code I write, I have put together a simple test app where I create the sregex object and can then test that the result is that which is exected. I am stuck with the use of before(...) Here is my test - which fails std::string strInput = "&9-A02FEfoo"; sregex re; re = bos >> as_xpr("&9-A02FE") >> before("foo"); if(regex_match(strInput, sm, re)) { strResult = "matched : " + sm[0].str(); } According to the documentation (v1.67) this should work. What am I doing wrong here ? Best regards Simon
On 17/04/2019 21:39, Simon Giddings wrote:
std::string strInput = "&9-A02FEfoo"; sregex re;
re = bos >> as_xpr("&9-A02FE") >> before("foo"); if(regex_match(strInput, sm, re)) { strResult = "matched : " + sm[0].str(); }
regex_match requires matching the entire string. "before" is a lookahead assertion, which means it doesn't actually consume the "foo" in the input, so the match fails. Use regex_search instead if you want to find partial matches.
participants (2)
-
Gavin Lambert
-
Simon Giddings