简体   繁体   中英

C++ Backslash escape character not transforming in Visual Studio 2017 Professional

I have a Visual Studio 2017 Professional. I am trying to very simply load a string variable in C++ with a regex pattern that contains backslashes:

\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b

As a test regex for a function. The regex is from here , meant to extract IP addresses from whatever piece of text.

If I paste the regex pattern as it is (ie - one backslash) the string variable will have no backslashes.

However, if I add another backslash, like you're supposed to, the string value will have two backslashes:

在此处输入图片说明

This does not happen in Eclipse. Why is this happening?

Visual Studio debugger shows special symbols as escape sequences (to be able to show \\n, for example, displaying large text in one line). Note that there's a small magnifying glass icon next to string entries. IF you press it VS will open a new window where it'll display unescaped (and potentially multiline) text.

By the way you need to escape \\b in your regex string too, even if it doesn't raise warnings (\\b is a special character).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM