I made this code right here on my first try with re2:
string s;
RE2::PartialMatch(".+\\.com","http://example.com/", &s);
It doesn't work; s
doesn't change and remains blank. I could change that first line to string s = "foo";
and after the second line runs, s
would stay as "foo"
.
What am I doing wrong?
There are two things wrong with your usage of PartialMatch
:
This should work:
RE2::PartialMatch("http://example.com/", "(.+\\.com)", &s);
Or if you don't want s to include the ".com" part:
RE2::PartialMatch("http://example.com/", "(.+)\\.com", &s);