Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将xml提取为两个字符串之间的字符串_C#_.net_Regex - Fatal编程技术网

C# 将xml提取为两个字符串之间的字符串

C# 将xml提取为两个字符串之间的字符串,c#,.net,regex,C#,.net,Regex,如何提取一些XML frame 0 push 'this' getVariable push 'g_data_1343488' push ' someXml' setMember end // of frame 0 我正在尝试使用正则表达式,但没有成功: foreach (var match in Regex.Matches(file, @"(?<=push ').*(?=')")) foreach(Regex.Matches(文件

如何提取一些XML

frame 0
    push 'this'
    getVariable
    push 'g_data_1343488'
    push ' 

    someXml'

    setMember
end // of frame 0
我正在尝试使用正则表达式,但没有成功:

foreach (var match in Regex.Matches(file, @"(?<=push ').*(?=')"))

foreach(Regex.Matches(文件@)中的变量匹配)(?这里有一种可能性。它是一个试图将单引号之间的内容识别为XML的正则表达式。对于这一点,它不是一个完美的正则表达式。如果可以使用,它实际上取决于您的要求。正则表达式必须越精确,读取起来就越困难。事实上,该表达式将不匹配所有XML,并且将与matc匹配还有一些无效的XML

例如,此正则表达式将匹配名称以数字开头的标记。它还将匹配XML结束标记和属性。您可以根据需要对其进行调整

这是:

push\s+'\s*<(\w+)(?:\s+\w+=(?:"[^"]*"|'[^']*'))*>(?:[^<]+|(?!</\1>)</?\w+(?:\s+\w+=(?:"[^"]*"|'[^']*'))*\s*/?>)*</\1>\s*'
检测根XML标记并捕获其名称。允许使用单引号和双引号分隔的属性:

<(\w+)(?:\s+\w+=(?:"[^"]*"|'[^']*'))*>

那么你想要最后一个“push”和“setMember”之间的文本吗?是的!如果我们把第一个组放进去,我想获取一些XML(而不是一些XML)P.s?
push\s+'\s*
<(\w+)(?:\s+\w+=(?:"[^"]*"|'[^']*'))*>
(?:[^<]+|(?!</\1>)</?\w+(?:\s+\w+=(?:"[^"]*"|'[^']*'))*\s*/?>)*
</\1>\s*'