how to escape a whole sequence of characters?

I’m using the following code to “execute” a regular expression in mfc c++

std::wregex rx(regularExpression,nFlags);
std::wcmatch res;
std::regex_search(inputString, res, rx);

This is used in a dialog where the user types in the regularExpression and I search it in my inputString.

The user can also select to not use a regular expression and just search normal text, but I want to have an option to search for “whole word” in the dialog.

When the user does select the “whole word” option and also the “regular expression” option, it is as easy as adding < and > to the beginning and end of the regularExpression, but when the user doesn’t select the regex option and keeps the “whole word” option I need to escape the “special characters”.

i.e.: "home.home" needs to become "home.home", "name" becomes "name" etc..

so how can I escape the whole string without having to escape every single special character?

Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.