Reputation: 11
So i want to check from a .txt file if there are valid proxies in it and i've been trying to get some matches without the regex ever working, i've decided to try a different approach, but i don't seem to understand anything with c++ regex, i don't understand how it's so different and poop, i either get a segmentation error 11 or no matches at all.
regex r("[[:digit:]][[:digit:]][[:digit:]].[[:digit:]][[:digit:]][[:digit:]].[[:digit:]][[:digit:]][[:digit:]].[[:digit:]][[:digit:]][[:digit:]]:[[:digit:]][[:digit:]]");
//regex r("[[:digit:]]{1,3}(.[[:digit:]]{1,3}){3}:[[:digit:]]{1,5}");
smatch sm;
if ( regex_search(text,sm,r) )
{
//we've got a match
}
Hope i can get some help
Upvotes: 1
Views: 59
Reputation: 1139
With regexes, the best way to deal with them is to start very small and build them up. Maybe start with just matching a single digit, then when you have that matching, match between one and three digits, then match between one and three digits followed by a full stop.
You should be warned that regex is relatively recent in the C++ standard library so it may not work at all on your system. If that's a problem for you, boost::regex will work.
you may also like to use literal raw strings R"(\d{1,3}.)" to encode your regex to avoid having to double up on backslashes "\d{1,3}\." due to the escaping in regular C strings. Start with the three chars R"( and end with the two )"
R"(\d{1,3}.)" might get you 1-3 digits folowed by a .
Upvotes: 1