使用RegExp获取实际的XML标记
我有一个XML,看起来像:使用RegExp获取实际的XML标记,xml,regex,Xml,Regex,我有一个XML,看起来像: <drawing><some other tags><Picture><some other tags></drawing><drawing><some other tags><Chart><some other tags></drawing> 我想提取 <drawing><some other tags><Cha
<drawing><some other tags><Picture><some other tags></drawing><drawing><some other tags><Chart><some other tags></drawing>
我想提取
<drawing><some other tags><Chart><some other tags></drawing>
目前我正在使用此RegExp:
/<drawing>.*?<Chart>.*?</drawing>/g
/.*?*?/g
但是,它会返回整个XML,因为它也是有效的。但我只想要第二次发生,无法得出解决方案。
提前感谢。关于使用正则表达式解析xml的所有免责声明,如果您想要正则表达式解决方案,请使用以下内容:
<drawing>(?:(?!</drawing>).)*?<Chart>.*?</drawing>
(?:(?!)*?*?
查看中的匹配
解释
匹配文字字符
匹配一个没有开头的字符(?:(?!)
懒洋洋地重复此匹配,直到*?
匹配文字字符
惰性地匹配字符直到*?