繁体   English   中英

正则表达式使用[^ \\ 000] *为0时无法匹配?

[英]RegEx cannot match when their are 0's using [^\000]*?

美好的一天,

是否可以使用正则表达式将所有内容放入标签中? 这是我的代码:

   MatchCollection matches = Regex.Matches(chek, "<bib-parsed>([^\000]*?)</bib-parsed>");

这是示例输入:

   <bib-parsed>
   <cite>
   <pubinfo>
   <pub-year><i>1984</i></pub-year>
   <pub-place>Albuquerque</pub-place>
   <pub-name>Maxwell Museum of Anthropology and the University of New Mexico Press        </pub-name>
   </pubinfo>
   <bkinfo>
   <btl>The Galaz Ruin: A Prehistoric Mimbres Village in Southwestern New Mexico</btl>
   </bkinfo>
   </bib-parsed>

上面的示例将被匹配,但是当在pubyear中有“ 0”之类的“ 2001”时,匹配将失败。

您输入的内容似乎是有效的XML。 如果是这种情况,请在System.XmlSystem.Xml.Linq使用XML解析器。 他们非常快。 对于包含多个块(例如您的示例)的输入字符串,请使用System.Xml.Linq命名空间对象:

var bibChunks = XDocument.Parse(yourXmlString)
                         .Descendants("bib-parsed")
                         .Select(e => e.Value);

foreach(string chunk in bibChunks) {
    // do stuff
}

这里的所有都是它的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM