This code isn\'t returning anything, am I escaping the w character the wrong way??
http://liveworkspace.org/code/3bRWOJ$38
#include
As @DanielFrey said, for an ordinary string literal you have to double-up the backslashes. With C++11 you can use a raw string literal instead: R"(\w)"
. The 'R' turns off handling of special characters, so the backslash is just a backslash. The parentheses mark the beginning and end of the raw string literal and are not part of the text.
The regular expression should contain \w
, consisting of two characters, \
and w
, hence your C++ source code should contain "\\w"
as you need to escape the backslash.