[英]Converting C# Regex into C++/CLI?
我在讓C#正則表達式適用於C ++時遇到麻煩。 在C#中,我有:
//using System.Text.RegularExpressions;
Regex YourName = new Regex("?<name>\w{3,16}");
但是在C ++中,這不正確匹配:
//using namespace System::Text::RegularExpressions;
Regex^ rx = gcnew Regex("?<name>\w{3,16}", static_cast<RegexOptions>(RegexOptions::Compiled));
其次是:
MatchCollection^ matches = rx->Matches( input ); //input=String^
匹配始終返回0計數。 我做的事真的很傻嗎? 將C#正則表達式轉換為C ++正則表達式是否需要做一些特殊的事情? 非常感謝您對此提出的任何見解。
您需要從編譯器轉義\\
,如下所示:
Regex^ rx = gcnew Regex("?<name>\\w{3,16}", static_cast<RegexOptions>(RegexOptions::Compiled));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.