問題:
我想使用正則表達式匹配某個xml子字符串(請參閱下面的ex。A)。問題是我無法匹配xml字符串末尾的斜槓,因爲它在Regex中是一個有意義的字符。我甚至試過在我的模型插入斜線前一個反斜槓逃脫斜線(見下面的代碼),但仍然不能使它工作...如何匹配xml字符串末尾的斜線?
問題:
赫克我如何使.NET正則表達式在xml字符串的末尾匹配斜槓?需要你的一些代碼忍者來幫助我。在此先感謝您的幫助,我的朋友。
的輸入:
<SummarySection id="_470">
<Title>Statistics</Title>
<Para id="_331"> Note: Estimated new cases in the United States in 2010:<Reference refidx="1"/> </Para>
</SummarySection>
守則:
// ex A: Pattern need to match (<Reference refidx="1"/>)
string xnodeptn = @"(<Reference refidx=""[a-zA-Z0-9]""/>)";
Regex refregex = new Regex(xnodeptn, RegexOptions.Compiled | RegexOptions.IgnoreCase);
MatchCollection mymatches = refregex.Matches(xe.ToString());
foreach (Match mch in mymatches)
{
...
}
string xnodeptn = @"(<Reference refidx=""[a-zA-Z0-9]""\/>)";
請不要在您的標題中添加諸如「(.NET Regex)」之類的內容。我們在[so]上使用了標籤。 –
嗯...這是一個很難我的朋友......也許這裏有人真的很聰明可以回答它... – m0rtimer
提供示例輸入。 –