最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【整理】UltraEdit中的Unix版本的正则竟然不支持超过2个或者关系

UltraEdit 3 type regex crifan 4800浏览 0评论

【背景】

自己之前,针对别人的问题已经给了答案,给出了正则的写法。

然后现在亲自去测试UltraEdit的正则,结果,竟然发现,要处理:

./xcode.configVpp.pl -frmrate 5 -height 720 -width 1280 -vidformat 1 -instance 0
./xcode.configVpp.pl -frmrate 5 -height 720 -width 1280 -vidformat 1 -instance 1
./xcode.configVpp.pl -frmrate 5 -height 720 -width 1280 -vidformat 1 -instance 2
./xcode.configVpp.pl -frmrate 5 -height 720 -width 1280 -vidformat 1 -instance 3
./xcode.configVpp.pl -frmrate 5 -height 720 -width 1280 -vidformat 1 -instance 4
./xcode.configVSC.pl -frmrate 5 -height 720 -width 1280 -vidformat 1 -instance 5
./xcode.configVSC.pl -frmrate 5 -height 720 -width 1280 -vidformat 1 -instance 6
./xcode.configVSC.pl -frmrate 5 -height 720 -width 1280 -vidformat 1 -instance 7
./xcode.configVpp.pl -frmrate 5 -height 720 -width 1280 -vidformat 1 -instance 8
./xcode.configVSC.pl -frmrate 5 -height 720 -width 1280 -vidformat 1 -instance 9
./xcode.configVSC.pl -frmrate 5 -height 720 -width 1280 -vidformat 1 -instance 10
./xcode.configVSC.pl -frmrate 5 -height 720 -width 1280 -vidformat 1 -instance 11
./xcode.configVpp.pl -frmrate 5 -height 720 -width 1280 -vidformat 1 -instance 12

将instance后面是0 4 8 12的行,中的720替换成576,1280替换成1024

【折腾过程】

1。然后试了半天,竟然结果不行。

先是用:

搜索->在文件中替换

ue search replace in file

然后试了很多个语法,先是提醒:

在文件中替换可能会修改驱动器上的许多文件

file replace will modify many files

不管他,点击是,然后结果还是无法实现匹配,更无法替换。

并且也试了几种写法:

-height\s+\d+\s+-width\s+\d+\s+-vidformat\s+1\s+-instance\s+(\d+)
-height\s+\d+\s+-width\s+\d+\s+-vidformat\s+1\s+-instance\s+0
-height\s+\d+\s+-width\s+\d+\s+-vidformat\s+1\s+-instance\s+(0|2|4|8)

结果都没用。

2.当时是在一个新建的文件中测试的,还没有保存。

然后去保存了新建文件到本地后,还是不行。

3.后来才搞懂,原来是替换对话框搞错了。

应该是:

搜索->替换

search replace ctrl r

然后才可以匹配和替换。

4.但是也还是存在一个问题:

已经选择了默认的Unix版本的正则了,然后用:

-height\s+\d+\s+-width\s+\d+\s+-vidformat\s+1\s+-instance\s+(0|2|4|8)

只能匹配找到最后那个8的那行:

use unix version regex replace abnormal only 8

 

很明显,不仅仅只是匹配和替换了8的那行,而且替换的结果也不对。

5.后来的后来,终于搞清楚了:

UltraEdit中的Unix版本的正则,对于(A|B)的语法,最多只支持2个。

所以,如果用:

-height\s+\d+\s+-width\s+\d+\s+-vidformat\s+1\s+-instance\s+(0|2)

就可以匹配到0和2的:

can match 0 and 2

但是去替换,结果也还是只能处理2,且替换结果也不对。

另外,再多加一个4:

-height\s+\d+\s+-width\s+\d+\s+-vidformat\s+1\s+-instance\s+(0|2|4)

都会有问题。和之前(0|1|4|8)的效果一样。

 

这点,后来也看到官网的例子了。

OR Expressions

 

OR Expressions

Currently UltraEdit only allows for the specification of two operands for an OR expression. You may search for an expression A or B as follows:

UltraEdit RegExp:

Find What: ^{John^}^{Tom^}

UNIX RegExp:

Find What: (John|Tom)

There should be nothing between the two expressions. You may combine A or B and C or D in the same search as follows:

UltraEdit RegExp:

Find What: ^{John^}^{Tom^} ^{Smith^}^{Jones^}

UNIX RegExp:

Find What: (John|Tom) (Smith|Jone)

This will search for "John" or "Tom" followed by "Smith" or "Jones".

6.然后再后来,经过折腾发现,其实此处用Perl的语法,上述的写法,就是支持的了:

for perl 0 2 4 8 can match

要去替换:

-height\s+\d+\s+-width\s+\d+\s+-vidformat\s+1\s+-instance\s+(0|2|4|8)
-height 576 -width 1024 -vidformat 1 -instance \1

也可以一次性,正确的替换4个:

use perl all four can be replaced

 

【总结】

虽然UltraEdit官网有了解释,说Unix版本的Or操作,最多支持2个,但是觉得这种做法,还是尼玛很变态的。

最后,一个普通的,简单的替换,搞得还必须用Perl去实现。。。

转载请注明:在路上 » 【整理】UltraEdit中的Unix版本的正则竟然不支持超过2个或者关系

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (2)

  1. 我写那篇文章《强烈推荐EditPlus 3.21》的时间是2011年01月19日,EditPlus 3.21发布的时间是2010-12-20。 我翻了一下Notepad++的发布日志,从Notepad++ 6开始才支持PCRE (Perl Compatible Regular Expressions),在此之前只支持功能很有限POSIX正则表达式,而Notepad++ 6的发布日期是2012-03-26。 UltraEdit在当时只支持它自己的那套乱七八糟的正则表达式,Unix和Perl也是后面才加上去的,所以我认为“Notepad++、UltraEdit、EmEditor等编辑器对于正则表达式的支持也不尽如人意”这句话并没有不妥之处。 至于现在EditPlus和Notepad++的正则表达式孰优孰劣,我几乎不用Notepad++,不敢妄加评论。
    Demon11年前 (2013-07-28)回复
    • 去确认了一下,你说的是对的。 而我之前,用notepad++的正则实现查找和替换,有证可查的,最早是2012-08-03,所以,也就是说: 即使再早一点,用到的notepad++的正则,那应该也是在2012-03-26之后用到的notepad++ 6之后的perl的正则,所以才会觉得好用的。 至于EditPlus和notepad++的正则,哪个好,我也没太多发言权。毕竟我只是用notepad++很多,但是用editplus很少。 目前感觉是: notepad++的正则,足够我用了; editplus,开启了TR1后的正则,也是够用了。
      crifan11年前 (2013-07-28)回复
87 queries in 0.165 seconds, using 22.14MB memory