2010-06-04 12 views
0

我無法讓我的C#正則表達式在C++中工作。在C#中,我有:將C#正則表達式轉換爲C++/CLI?

//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++正則表達式需要做些什麼?非常感謝您爲此付出的任何光芒。

+1

這是C#,不是C. C沒有任何類型的正則表達式。 – 2010-06-04 20:11:39

回答

3

你需要躲避\從編譯器,像這樣:

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

他不需要在C#中逃脫嗎? OP,你確定你的C#版本沒有;沒有一個字符串(以@「...」開頭)? – 2010-06-04 20:14:00

+0

哈,是的,你是對的。完全錯過了。這確實解決了,謝謝你們。 – Dororo 2010-06-04 20:21:10

相關問題