文本编辑常用正则表达式(不定期更新) - ○白子○ 的Blog

文本编辑常用正则表达式(不定期更新)

[ 2009-09-02 21:12:22 | Author: seaboat ]
Font Size: Large | Medium | Small
从事代码别想工作时间长了,用正则表达式查找替换文本也就成为家常便饭。
编辑文本,如果不会用正则表达式,效率要打折扣,这是我的一点体会。

记录一下最近常用的表达式:

-------------------------------
js多余逗号
,[\s\r\n]*\}
,[\s\r\n]*\]

-------------------------------
行尾空格
([^\s])\s+$
-------------------------------
一个或多个汉字
[\x{4e00}-\x{9fa5}]+
-------------------------------
php 变量名替换: $var_name -> $varName
替换前: (\$\w+)_(\w)(\w*)
替换后: \1\U\2\L\3
-------------------------------
从HTML文本抽取 name="..." 中的name属性
替换前: .*\sname="([^"]+)".*
替换后: \1
-------------------------------

其他常用的暂时想不起来,以后补充。

注:
以上表达式,主要在 EmEditor 下使用。
EmEditor 下正则替换很简单,替换字符串()中的内容,在被替换的字符串里,按顺序是 \1 \2 \3 ...
[Last Modified By seaboat, at 2009-09-24 03:51:24]
Comments Feed Comments Feed: http://www6.webng.com/seaboat/feed.asp?q=comment&id=757

There is no comment on this article.

Post Comment
Smilies
[smile] [confused] [cool] [cry]
[eek] [angry] [wink] [sweat]
[lol] [stun] [razz] [redface]
[rolleyes] [sad] [yes] [no]
[heart] [star] [music] [idea]
Enable UBB Codes
Auto Convert URL
Show Smilies
Hidden Comment
Username:   Password: