Regex \w escaping in C++11

后端 未结 2 756
情歌与酒
情歌与酒 2021-01-15 17:04

This code isn\'t returning anything, am I escaping the w character the wrong way??

http://liveworkspace.org/code/3bRWOJ$38

#include 
         


        
相关标签:
2条回答
  • 2021-01-15 17:43

    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.

    0 讨论(0)
  • 2021-01-15 17:44

    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.

    0 讨论(0)
提交回复
热议问题