I'm having trouble getting my C# Regex working for C++. In C# I have:
//using System.Text.RegularExpressions;
Regex YourName = new Regex("?<name>\w{3,16}");
but in C++ this does not correctly match:
//using namespace System::Text::RegularExpressions;
Regex^ rx = gcnew Regex("?<name>\w{3,16}", static_cast<RegexOptions>(RegexOptions::Compiled));
followed by:
MatchCollection^ matches = rx->Matches( input ); //input=String^
Matches always return 0 count. Am I doing something really silly? Is there something special you need to do to convert C# regex into C++ regex? Many thanks for any light you can shed on this.
您需要从编译器转义\\
,如下所示:
Regex^ rx = gcnew Regex("?<name>\\w{3,16}", static_cast<RegexOptions>(RegexOptions::Compiled));
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.