问题:
我想使用正则表达式匹配某个 xml 子字符串(参见下面的示例 A)。问题是我无法匹配 xml 字符串末尾的斜杠,因为它是正则表达式中有意义的字符。我什至尝试通过在模式中的斜杠之前插入反斜杠来转义斜杠(请参见下面的代码),但仍然无法使其工作...
问题:
我到底如何使 .NET Regex 匹配 xml 字符串末尾的斜杠???需要你们中的一些编码忍者来帮助我。预先感谢您的帮助,我的 friend 。
输入:
<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]""\/>)";
最佳答案
我相信斜杠“/”is not a reserved character in regex 。所以我认为模式一定存在不同的问题。
关于.net - 如何匹配 xml 字符串末尾的斜杠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7289040/