1

UltraEdit 文本编辑器包括用于搜索的 Perl 和 Unix 兼容的正则表达式引擎。

我希望能够匹配一个字符串行:

<branch id="attribute">
    <leaf id="attribute"/>
    <leaf id="attribute"/>
    <leaf id="attribute"/>
</branch>

像这样:

/<branch id="attribute">.*</branch>/gis

有没有办法使用 UltraEdit 来完成这个?

4

3 回答 3

3

如果您将 (?s) 放在模式的开头,它将启用单行模式,因此 \r\n 不会被排除在匹配之外。*

例如,以下匹配整个分支元素(在 UEStudio 6 中使用 Perl 样式的正则表达式):

(?s)<branch id="attribute">.*</branch>

做一个小实验,也支持其他一些 Perl 选项。例如,开头的 (?sx-i) 将是单行,忽略模式中的额外空格,区分大小写(似乎默认为不区分大小写)。

于 2009-01-29T21:46:38.743 回答
2

如果您选择了 Perl 正则表达式,您可以执行以下操作:

<branch id="attribute">[\s\S]*</branch>

其中 \s 是任何空白字符,包括换行符和回车符,而 \S 是任何其他字符。请注意,默认情况下这是贪婪的,因此如果您有以下字符串:

<branch id="attribute">
  <leaf id="attribute"/>
  <leaf id="attribute"/>
  <leaf id="attribute"/>
</branch>
<branch id="attribute">
  <leaf id="attribute"/>
  <leaf id="attribute"/>
  <leaf id="attribute"/>
</branch>

那么一个正则表达式将找到整个字符串作为一个匹配项。如果你不想这样做,那么添加?如下:

<branch id="attribute">[\s\S]*?</branch>

从答案中可以看出,在 UltraEdit 中有很多方法可以实现这一点!

注意:使用 UltraEdit 14.20 测试。

于 2009-01-29T22:05:04.213 回答
-2

你有没有尝试过:

/<branch id="attribute">[.\n]*</branch>/gis
于 2009-01-29T21:53:32.177 回答