2013-03-01 22 views
1

我試圖得到與此表達式相反的結果,它給了我一些麻煩。C#正則表達式排除具有隨機元素名稱的標記

Ex。

expression: (?<={{)(.*?)(?=}}) 
string: this is a question with a textbox {{textbox}} ok 
results: textbox 

尋找類似

expression: !(?<={{)(.*?)(?=}}) 
string:this is a question with a textbox {{textbox}} ok 
results: this is a question with a textbox ok 

另外,我要指出,最新的{{}}的並不總是文本框,將是隨機的字母。

回答

1

如何進行更換?

string replaced = yourRegex.Replace(original, string.Empty); 

replaced將是你的「匹配」。而且你不再需要這些斷言。