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

【吐槽】Editplus中的正则表达式,功能虽然不垃圾,但相关的文档却很垃圾

EditPlus TR1 crifan 5631浏览 0评论

话说,要帮别人,将:

刀白凤 丁春秋 马夫人 马五德 小翠 于光豪 巴天石 不平道人 邓百川 风波恶 甘宝宝 公冶乾 木婉清 包不同 天

中的内容,通过Editplus的正则表达式,替换成:

刀白凤
丁春秋
马夫人
马五德
小翠
于光豪
巴天石
不平道人
邓百川
风波恶
甘宝宝
公冶乾
木婉清
包不同
天

1. 然后就去下载一个Editplus。

注:期间,想去Editplus主页下载的,结果主页的download页面:

http://www.editplus.com/download.html

等了N多秒,始终打不开,只好去另外的:

EditPlus V3.41.1152 绿色烈火汉化共享版

下载的。

2.下载下来之后,就去写了个正则表达式,去试试:

(\S+)\s+

结果竟然无法替换:

slash s can not replace

觉得很奇怪,竟然不工作。

3. 然后就去看看其帮助文件,找到了正则表达式的部分的介绍,发现竟然是:

editplu reg manual

很明显,里面竟然不支持最普通的

\S

\s

\d

等转义的。真是够悲催的。

就这样,其也好意思说自己支持正则(查找和替换)啊。

相比Notepad++的正则,弱的不要太多。

 

注:不了解的去看我写的:

Notepad++的正则表达式替换

 

4.没办法,那只能按照其所支持的,利用点’.’去匹配这些中文(因为没有\S),利用空格字符本身’ ‘去匹配空格了(因为没有\s)。

结果是,利用:

(.+) +

竟然只实现了替换了一个:

use point and space just replace one

而不是正常的,应该去匹配上述的所有的人名的。

至此,对正则熟悉的人,也都知道我在说什么。

尼玛Editplus,不仅仅是正则功能弱,简直就是垃圾啊。

然后又试了试其他的写法:

(1)用:

(.+?) +

一个都没替换成。

(2)以为多个人名中间的字符,不是空格而是制表符呢,所以也试过了:

(.+?)\t+

结果也是一个没替换到。

 

5.折腾了半天,都以失败告终。

就在打算放弃的时候,最终,竟然是,无意间发现的,可以通过:

(..) +

实现最终所要替换的效果:

two point and space can replace all

而此处的正则:

(..) +

很明显只是,匹配两个字符(不管你是汉字还是英文字符(和其他)),然后是空格(至少一个)

但是实际上,此处两个点’..’的效果,却相当于了点加’.+’,去匹配多个汉字了。

日啊,真尼玛够垃圾的。

极度怀疑,开发Editplus的那帮人,会不会正则。

尼玛,不懂也不能瞎写,瞎实现啊。

 

【总结】

Editplus,正则表达式这个功能,不仅仅是功能不全,而且还是bug一堆,而且还诡异。

即用正则的语法,无法实现功能,碰巧用了一个不正确的写法,且诡异的实现了某个特定的效果。

 

真希望,有机会和Editplus开发人员,好好聊聊。看看他们到底,都是从哪里学习到的正则。。。。


【后记 2012-12-25】

后来,帮别人去实现在EditPlus中写正则,从:

up/114567/img<br />up/120305/img<br />up/1205/img

中“查找12开头、数字为4位的字符,即 up/1205/img”

所以就去写正则,本来以为直接去用:

up/12[0-9]{2}

就可以的,结果竟然发现,Editplus中的正则的支持,竟然烂到,来{m,n}指定个数的,这个最最基本的正则的语法,都不支持。。。

帮助文件中的解释是:

Regular Expression

< Prev | Next >

Regular expression is a search string that contains normal text plus special characters which indicate extended searching options. Regular expression allows more sophisticated search and replace.

For example, you can find any digit by using regular expression "[0-9]". Similarly you can find any matching character that is NOT digit by using regular expression "[^0-9]".

EditPlus supports following regular expressions in Find, Replace and Find in Files command.

Expression

Description

\t

Tab character.

\n

New line.

.

Matches any character.

|

Either expression on its left and right side matches the target string. For example, "a|b" matches "a" and "b".

[]

Any of the enclosed characters may match the target character. For example, "[ab]" matches "a" and "b". "[0-9]" matches any digit.

[^]

None of the enclosed characters may match the target character. For example, "[^ab]" matches all character EXCEPT "a" and "b". "[^0-9]" matches any non-digit character.

*

Character to the left of asterisk in the expression should match 0 or more times. For example "be*" matches "b", "be" and "bee".

+

Character to the left of plus sign in the expression should match 1 or more times. For example "be+" matches "be" and "bee" but not "b".

?

Character to the left of question mark in the expression should match 0 or 1 time. For example "be?" matches "b" and "be" but not "bee".

^

Expression to the right of ^ matches only when it is at the beginning of line. For example "^A" matches an "A" that is only at the beginning of line.

$

Expression to the left of $ matches only when it is at the end of line. For example "e$" matches an "e" that is only at the end of line.

()

Affects evaluation order of expression and also used for tagged expression.

\

Escape character. If you want to use character "\" itself, you should use "\\".

The tagged expression is enclosed by (). Tagged expressions can be referenced by \0, \1, \2, \3, etc. \0 indicates a tagged expression representing the entire substring that was matched. \1 indicates the first tagged expression, \2 is the second, etc. See following examples.

Original Search Replace Result

abc (ab)(c) \0-\1-\2 abc-ab-c

abc a(b)(c) \0-\1-\2 abc-b-c

abc (a)b(c) \0-\1-\2 abc-a-c

后来实在不行了,只能写成:

up/12[0-9][0-9]

结果却又发现,竟然其会同时匹配到

up/120305/img

所以,最后的最后,只能用:

up/12[0-9][0-9][^0-9]

了:

finally use basic regex to match

 

提示:

此处还要必须选择Wrap at the end of file,才能搜索到的。。。

 

【总结】

见过烂的正则,比如Java中正则,功能不全之外,用法还很诡异。

但是真的是没见过这么烂的正则的实现。。。EditPlus,真的让我在这方面开眼了。。。

如果谁要把EditPlus的正则,和Notepad++的正则去比较的话,那绝对是对Notepad++的正则的侮辱。

不了解的,自己去看:

Notepad++的正则表达式替换

 


【后记 2012-12-16】

后来,经过haokeyy的提醒,自己去 开启使用TR1正则:

Tools->Preferences->General -> Use TR1 regular expression

tools preference

general use tr1 regular expression

 

然后再去试试,果然支持使用:

up/12\d{2}/img

就可以成功匹配所要的内容的:

after tr1 can use normal regex

 

但是有个疑问的是,为何,在Editplus的内置手册中,

在正则的解释中,为何没有提到,如此重要的TR1(虽然我之前也没听说过这个名词)的正则呢?

难道仅仅是手册的失职???

有点费解。

毕竟,正常的逻辑是:

作为写文档的,即使你的

Use TR1 regular expression

是属于别处的配置,但是对于正则表达式的查找的话,本身就应该是相关的内容,而且不同设置会导致正则的使用不同。

所以,按理来说,有必要,极其的必要,在正则的解释中,说清楚,还有个另外的TR1,

如果你选上和不选上,会导致正则的功能,完全不同。

反正,对于其文档为何不加上此注释,还是无语了。。。。

 

再次谢过haokeyy。

转载请注明:在路上 » 【吐槽】Editplus中的正则表达式,功能虽然不垃圾,但相关的文档却很垃圾

发表我的评论
取消评论

表情

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

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

网友最新评论 (5)

  1. 看到作者的此文我淡定了,使用editplus++十几年,我原来一直以为自己的正则没学好!看来是editplus的程序员没学好
    hovel8年前 (2016-09-04)回复
  2. 首先选项里面的TR1 RE选项你就没关注过;然后你也没注意汉化版的手册明显与原版落后了好多。你也没去看What's New,碰到这样的问题只能怪自己咯。
    x9年前 (2015-08-06)回复
  3. 我觉得你有很笨,/s不支持,不代表空格(SP)也不支持啊。直接采用(. )*就ok了
    9年前 (2015-06-30)回复
  4. 我用的 editplus v3.5 在 Tools - Preferences 设置中 选中 Use TR1 regular expression 就可以了.
    haokeyy11年前 (2012-12-26)回复
  5. 感觉emeditor的正则表达式也很诡异。&竟然不是表示查找匹配的内容。
    four511年前 (2012-12-05)回复
87 queries in 0.172 seconds, using 22.08MB memory