Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Exception when escaping "\" in Boost Regex

I’m always getting an exception when trying to escape a backslash like this:

        boost::regex shaderRegex{ "test\\" };

Am I doing something wrong?

Unhandled exception at 0x00007FFD13034FD9 in project.exe: Microsoft C++ 
exception: boost::wrapexcept<boost::regex_error> at memory location 

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

A literal backslash would be

boost::regex shaderRegex{ "test\\\\" };

In a C++ string, the characters \\ represent a single backslash character.

To represent a regex literal (escaped) backslash, you would need two of those.

If this looks confusing, you can also use a C++11 raw string literal.

boost::regex shaderRegex{ R"(test\\)" };
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading