jeudi 16 avril 2015

C++11 Regular Expression with one or more whitespaces

Using regular expressions in C++11, I'm trying to detect single HTML tags that end in /> or / >, such as <br/> or "<hr/ >.


With Boost, I used this regex string: "<.*/\\s*>" It worked fine, but the C++11 regex module doesn't accept it.


So I have tried this code: bool IsSingle(string sTag) { string regex_str = "<.*/((\s)*)>"; // \s* zero or more whitespaces regex reg1(regex_str, regex_constants::icase); bool bb = regex_search(sTag, reg1); return bb; } 2 problems:


1) it raises an error warning: warning: unknown escape sequence: '\s' [enabled by default]


2) it doesn't work.


With sTag arguments such as <br/> or <br/ >, the function returns 0.


What am I doing wrong?


Thanks!


PS: using C++11 with gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1), and Nebeans IDE 8.0.2.


Aucun commentaire:

Enregistrer un commentaire