I want to initialize a std::wregex with a std::wstring, but if I give a std::wstring that do not conform to regular expression syntax(for example, std::wstring(L"*")), the initialization will crash.
std::wstring userRegex;
std::wcout << L"input regex: ";
std::wcin >> userRegex;//for example,userRegex == std::wstring(L"*")
std::wregex pattern = std::wregex(userRegex) //crash
try-catch is not allowed in my code.
I want to ensure that any std::wstring
input will not cause a crash. If this std::wstring
does not follow the syntax rules of regular expressions, my code should inform me and return it in advance.