boost::xpressive use of before(...)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

boost::xpressive use of before(...)

Boost - Users mailing list
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

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: boost::xpressive use of before(...)

Boost - Users mailing list
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.
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users