我正在尝试使用正则表达式捕获 xml 文档中两个标签之间的一系列标签



我试图使用正则表达式捕获xml文档中两个标记之间的一系列标记,但它会捕获文档中的每一个出现。

<Mods>
<unsignedlong>123456</unsignedlong>
</Mods>
<Administrators>
<unsignedlong>12345678910111213</unsignedlong>
</Administrators>
<Banned>
<unsignedlong>12345678910111213</unsignedlong>
</Banned>

这是我需要从中获取以下内容的代码。

<unsignedlong>12345678910111213</unsignedlong>

我一直在使用

<unsignedLong>(?<ModID>d+)</unsignedLong>

但这会返回整个文件中的所有值——我需要一个字符串来从中挑出未签名的long

<Mods></Mods>

编辑

这是用于识别正则表达式

的web应用程序中

这应该可以完成您需要的几个修改:

// Match a Regex and Do Stuff
public void showMatch(string input, string expr)
{
    MatchCollection mc = Regex.Matches(input, expr);
    // Index
    int num = 0;
    // "For each match in the match collection, Do this"
    foreach (Match m in mc)
    {
        string tm = m.ToString();
        num++;
        if (num == 1)
        {
            // Do Stuff if 1 match.
        }
        if (num == 2)
        {
            // Do Stuff if 2 matches.
        }

为了匹配你想要的,你可以使用这个:

showMatch(input, @"(?:[0-9]+){17}");

最新更新