正则表达式解析html元素并更改它们

时间:2014-04-02 13:34:20

标签: regex eclipse

现在我需要在我的所有html页面中更改我的一个coponents的属性名称。要做到这一点,我想要正则表达式搜索并在eclipse中替换它。(eclipse regex syntax

该组件如下所示:

<exa:mycomponent attribute1="attr1" attribute2 ="attr2" ... >

<exa:mycomponent attribute1="attr1"
             attribute2 ="attr2" ... >

我用

尝试了
 <exa:mycomponent ([\S\s]*)attribute1([\S\s]*)>

但它也返回与“mycomponent”不同的组件,因为那里有一个“mycomponent”而另一个组件使用该属性,如下所示:

<exa:mycomponent attribute2 ="attr2" ... >

<exa:myothercomponent attribute1 ="attr2" ... >

将取代“myothercomponent”的“attribute1”

有没有办法在第一个“&gt;”“打破”以防止它找到错误的组件? 我用

试了一下
 <exa:mycomponent ([\S\s^>]*)attribute1([\S\s^>]*)>

但它不起作用。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

尝试使用此模式:

<exa:(mycomponent)([\S\s]attribute1[\S\s]+?)>

示例: http://regex101.com/r/rA8rE0