TheMeaningfulEngineer
TheMeaningfulEngineer

Reputation: 16349

Regex passing on regex tester but failing in qt

I'm using regex to test if iptables have been set. Here is a stripped down version of what trying to achieve.

QRegExp rx_preroute(".*DNAT\s*udp\s*--\s*anywhere\s*192\.168\.13\.115\s*to:10\.5\.110\.123:7891.*");
QString out = "DNAT       udp  --  anywhere             192.168.13.115       to:10.5.110.123:7891";
qDebug() << rx_preroute.exactMatch(out);
//prints out false

However, if I do the same thing in the regex checker (http://regexpal.com/ ) it passes. Also it seem to me, by manually checking the pattern, that it should pass. Qt is running on the default regex syntax. I experience the same behavior with setPatternSyntax(QRegExp::RegExp2).

Upvotes: 0

Views: 530

Answers (1)

Toto
Toto

Reputation: 91405

You should double escape ie. \\s and \\. instead of \s and \.

Upvotes: 4

Related Questions