xml中的正则表达式

时间:2013-02-07 09:37:30

标签: regex eclipse

Eclipse软件具有搜索正则表达式的功能。 我想搜索xml父节点不是<version>0.0.1-SNAPSHOT</version>的所有<parent>字符串。

最简单的方法是什么?

1 个答案:

答案 0 :(得分:1)

编辑:完成重写。

只要<parent>标签不能嵌套,这是可能的,但只有这样(并且所有关于不尝试将XML与正则表达式匹配的常见警告都适用。一旦你有评论或CDATA部分在您的XML中,所有赌注都已关闭。

(?s)<version>0\.0\.1-SNAPSHOT</version>(?!(?:(?!</?parent>).)*</parent>)

<强>解释

(?s)              # Turn on singleline matching mode
<version>0\.0\.1-SNAPSHOT</version> # Match this string
(?!               # but only do this if it's impossible to match this regex here:
 (?:              # Try to match...
  (?!</?parent)   #  (as long as there is no <parent> or </parent> tag ahead)
  .               #  any character
 )*               # any number of times
 </parent>        # Then match </parent>
)                 # End of lookahead