Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.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# 标记内标记和最后匹配标记的正则表达式匹配_C#_Regex - Fatal编程技术网

C# 标记内标记和最后匹配标记的正则表达式匹配

C# 标记内标记和最后匹配标记的正则表达式匹配,c#,regex,C#,Regex,我试图用包含转义字符串的数据解析一些xml标记 一些样品 other tags with our without newlines <tag name="abc1" type="bcd" value="test"><tag name="abc2" type="bcd" value="test"> other tags other tags with our without newlines <tag name="abc2" type="bcd" value="&

我试图用包含转义字符串的数据解析一些xml标记 一些样品

other tags with our without newlines
<tag name="abc1" type="bcd" value="test"><tag name="abc2" type="bcd" value="test">  
other tags other tags with our without newlines
<tag name="abc2" type="bcd" value="<w:test xmlns:wst=&quot;http://schemas.xmlsoap.org/ws/2005/02/trust&quot;><a xmlns:&quot;a:b:c:ddd:&quot;>XEduAjr8MoV</a></w:test>">

由于
(?*)
的原因,我在组合多个匹配项时遇到了问题,因为如果两个匹配项都是同一行
有什么办法可以解决这个问题吗?有更好的方法吗?

不建议使用正则表达式模式解析xml文件。这是因为xml涉及/需要深度嵌套。

不建议使用正则表达式模式解析xml文件。这是因为xml涉及/需要深度嵌套。

众所周知,除非没有复杂的标记和奇怪的字符集,否则不应使用regex解析xhtml

但是,如果您想使用正则表达式,对于您的特定示例,您必须使用非贪婪的(或懒惰的)量词:

<tag name="(?<name>\w*?)" type="(?<id>\w*?)" value="(?<value>.*?)">
                                                       HERE ---^
also I put it here ---^------------------^ 
since it is more secure, but it is not needed

这里---^
我也把它放在这里--^--------------------------^
因为它更安全,但它不是必需的

众所周知,不应该使用regex解析xhtml,除非您没有复杂的标记和一组奇怪的字符

但是,如果您想使用正则表达式,对于您的特定示例,您必须使用非贪婪的(或懒惰的)量词:

<tag name="(?<name>\w*?)" type="(?<id>\w*?)" value="(?<value>.*?)">
                                                       HERE ---^
also I put it here ---^------------------^ 
since it is more secure, but it is not needed

这里---^
我也把它放在这里--^--------------------------^
因为它更安全,但它不是必需的

最好不要使用正则表达式解析xml/html。。。使用xslt…最好不要使用正则表达式解析xml/html。。。使用xslt…可能重复的
var regex = new Regex(regstr, RegexOptions.Multiline);
MatchCollection mc = regex.Matches(sourcestring);
<tag name="(?<name>\w*?)" type="(?<id>\w*?)" value="(?<value>.*?)">
                                                       HERE ---^
also I put it here ---^------------------^ 
since it is more secure, but it is not needed