Reputation: 1861
I have such a regular expression
boost::regex isAgent
("Mozilla/\d[.]\d \(Windows NT \d[.]\d; (Win64; x64;|WOW64;)?(.*?)\) Gecko/\d{8} Firefox/\d\d[.]\d",
boost::regex::perl);
if (boost::regex_search(auxAgent.c_str(), match, reg)){...}...
i know that in auxAgent
i have exacly Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0
on this page http://gskinner.com/RegExr/?37em3 everything matches but not in boost, what am i doing wrong?
Upvotes: 0
Views: 184
Reputation: 651
I think Pawel Stawarz is correct. You should escape the backslashes. But here are all the characters you need to escape:
^ . $ | ( ) [ ] * + ? \ /
Replace \ with \\
and
Replace ? with \?
etc.
Source: How to escape a string for use in Boost Regex
Upvotes: 1
Reputation: 4012
In C++, the character \
needs to be escaped. So if you want to escape anything, you need to do \\
. That should fix the problem. Whenever you use the backslash in a string, you need to escape it like that. If you ever need to find it in a string with the regex, you'll need to search for it with \\\\
.
Upvotes: 1