简体   繁体   English

将C#正则表达式转换为C ++ / CLI?

[英]Converting C# Regex into C++/CLI?

I'm having trouble getting my C# Regex working for C++. 我在让C#正则表达式适用于C ++时遇到麻烦。 In C# I have: 在C#中,我有:

 //using System.Text.RegularExpressions;
 Regex YourName = new Regex("?<name>\w{3,16}");

but in C++ this does not correctly match: 但是在C ++中,这不正确匹配:

 //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. 匹配始终返回0计数。 Am I doing something really silly? 我做的事真的很傻吗? Is there something special you need to do to convert C# regex into C++ regex? 将C#正则表达式转换为C ++正则表达式是否需要做一些特殊的事情? Many thanks for any light you can shed on this. 非常感谢您对此提出的任何见解。

您需要从编译器转义\\ ,如下所示:

Regex^ rx = gcnew Regex("?<name>\\w{3,16}", static_cast<RegexOptions>(RegexOptions::Compiled));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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