推荐:EditPlus+正则表达式,处理中等大小的文本

推荐RT,
如果哪个哥们发现了比EditPlus对正则支持的更NB的编辑器(标准正则表达式),请通知我,谢谢啊。支持非标准的正则就不要提了,如UE等。目前的EditPlus支持的正则表达式也不是很完全,比如\s空格就不支持。

为啥要文本中等大小?

太大了正则效率不高,正则表达式的执行是很消耗CPU时间的。
太小了手工改改就OK了,要是你正则不熟练,还要想半天。
文本太大的话我会用Ruby或者JS这种方便执行的脚本语言来做。

我觉得我对正则表达式的使用范围越来越广了,
而且windows下配合Editplus进行文本处理真方便。

本来刚才要写一大段的C代码,不断的重复,超级麻烦,用正则表达式把我要的URL扣出来,
然后直接嵌入进代码片段后,立刻搞定,剩下无数工作量啊。

原始文本:

 00:00:00.002	0.001	0	GET	(Cache)	application/javascript	http://w.alisoft.com/static/jquery-1.3.2.min.js
00:00:00.037 0.001 0 GET (Cache) application/javascript http://w.alisoft.com/space/js/util.js
00:00:00.041 0.001 0 GET (Cache) text/css http://w.alisoft.com/static/reset.css
00:00:00.043 0.001 0 GET (Cache) text/css http://w.alisoft.com/static/global_back.css
00:00:00.045 0.001 0 GET (Cache) text/css http://w.alisoft.com/static/index/index.css
00:00:00.046 0.001 0 GET (Cache) text/css http://w.alisoft.com/static/module/module.css
00:00:00.048 0.001 0 GET (Cache) application/javascript http://w.alisoft.com/static/module/module.js
00:00:00.084 0.001 0 GET (Cache) application/javascript http://w.alisoft.com/space/js/CookieUtil.js
00:00:00.087 0.001 0 GET (Cache) application/javascript http://w.alisoft.com/space/js/feed.js
00:00:00.000 0.091 0 GET (Cache) text/html;charset=UTF-8 http://w.alisoft.com/space/home/homePage.do
00:00:00.091 0.001 0 GET (Cache) application/x-javascript http://img.im.alisoft.com/webim/js/website.js
00:00:00.099 0.001 0 GET (Cache) application/javascript http://w.alisoft.com/static/index/index.js
00:00:00.103 0.001 0 GET (Cache) application/javascript http://w.alisoft.com/static/base.js
00:00:00.110 0.001 0 GET (Cache) text/plain;charset=utf-8 http://w.alisoft.com/space/layout/layout.do
00:00:00.150 0.002 0 GET (Cache) text/plain;charset=utf-8 http://w.alisoft.com/space/friend/loadGroupInfo.do
00:00:00.209 0.025 3458 GET 200 text/x-json;charset=UTF-8 http://apps.w.alisoft.com/apps/mission/mission!cmission.do?jsoncallback=jsonp1247116589623&_=1247116589794
00:00:00.246 0.001 0 GET (Cache) application/x-javascript http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js
00:00:00.207 0.045 13751 GET 200 text/x-json;charset=UTF-8 http://apps.w.alisoft.com/apps/mood/homeMoodInit.do?jsoncallback=jsonp1247116589622&_=1247116589794
00:00:00.252 0.002 0 GET (Cache) application/x-javascript http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js
00:00:00.237 0.021 2207 GET 200 text/x-json;charset=UTF-8 http://apps.w.alisoft.com/apps/poke/poke!listPokeInfoForFriend.do?jsoncallback=jsonp1247116589624&_=1247116589825
00:00:00.239 0.031 815 GET 200 text/x-json;charset=UTF-8 http://apps.w.alisoft.com/apps/poke/poke!listPokeInfoForNonFriend.do?jsoncallback=jsonp1247116589625&_=1247116589825
00:00:00.240 0.043 2207 GET 200 text/x-json;charset=UTF-8 http://apps.w.alisoft.com/apps/poke/poke!listPokeInfoForFriend.do?jsoncallback=jsonp1247116589626&_=1247116589825
00:00:00.321 0.031 10410 GET 200 text/x-json;charset=UTF-8 http://apps.w.alisoft.com/apps/face/face.do?jsoncallback=jsonp1247116589627&_=1247116589903
00:00:00.216 0.204 510 GET 200 text/html;charset=UTF-8 http://w.alisoft.com/space/home/homePage!homePageMessages.do?token=1247116589794
00:00:00.287 0.422 19543 GET 200 application/x-javascript http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js?_=1247116589872
00:00:00.233 0.338 1229 POST 200 text/html;charset=UTF-8 http://w.alisoft.com/space/feed/portal!feedList.do?token=1247116589809
00:00:00.224 0.618 3178 GET 200 text/html;charset=UTF-8 http://w.alisoft.com/space/friend/homePageFriendWidget.do?token=1247116589794
00:00:00.871 0.002 492 GET 404 text/html; charset=iso-8859-1 http://amos.im.alisoft.com/mullidstatus.aw?beginnum=1&uids=


看一下啊,所有带Cache的行我都不要,这么做:

Ctrl+H,

正则表达式那里填入:

.*Cache.*


然后勾选正则表达式,替换,去掉换行符之后是这样:

00:00:00.209	0.025	3458	GET	200	text/x-json;charset=UTF-8	http://apps.w.alisoft.com/apps/mission/mission!cmission.do?jsoncallback=jsonp1247116589623&_=1247116589794
00:00:00.207 0.045 13751 GET 200 text/x-json;charset=UTF-8 http://apps.w.alisoft.com/apps/mood/homeMoodInit.do?jsoncallback=jsonp1247116589622&_=1247116589794
00:00:00.237 0.021 2207 GET 200 text/x-json;charset=UTF-8 http://apps.w.alisoft.com/apps/poke/poke!listPokeInfoForFriend.do?jsoncallback=jsonp1247116589624&_=1247116589825
00:00:00.239 0.031 815 GET 200 text/x-json;charset=UTF-8 http://apps.w.alisoft.com/apps/poke/poke!listPokeInfoForNonFriend.do?jsoncallback=jsonp1247116589625&_=1247116589825
00:00:00.240 0.043 2207 GET 200 text/x-json;charset=UTF-8 http://apps.w.alisoft.com/apps/poke/poke!listPokeInfoForFriend.do?jsoncallback=jsonp1247116589626&_=1247116589825
00:00:00.321 0.031 10410 GET 200 text/x-json;charset=UTF-8 http://apps.w.alisoft.com/apps/face/face.do?jsoncallback=jsonp1247116589627&_=1247116589903
00:00:00.216 0.204 510 GET 200 text/html;charset=UTF-8 http://w.alisoft.com/space/home/homePage!homePageMessages.do?token=1247116589794
00:00:00.287 0.422 19543 GET 200 application/x-javascript http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js?_=1247116589872
00:00:00.233 0.338 1229 POST 200 text/html;charset=UTF-8 http://w.alisoft.com/space/feed/portal!feedList.do?token=1247116589809
00:00:00.224 0.618 3178 GET 200 text/html;charset=UTF-8 http://w.alisoft.com/space/friend/homePageFriendWidget.do?token=1247116589794
00:00:00.871 0.002 492 GET 404 text/html; charset=iso-8859-1 http://amos.im.alisoft.com/mullidstatus.aw?beginnum=1&uids=


然后我要把里面所有http://的URL填入web_url("\2","URL=\1",LAST)之后,
\2是名字,我用每个请求最后的处理方法名代替,它位于url中的最后一个/之后,?之前。
\1是URL,带参数,http://开始到该行的结尾。

这么做:

正则表达式:

^.*(http:.*\/(.*)\?.*)$


被替换的地方:

web_url("\2","URL=\1",LAST);


替换后的文本:

web_url("mission!cmission.do","URL=http://apps.w.alisoft.com/apps/mission/mission!cmission.do?jsoncallback=jsonp1247116589623&_=1247116589794",LAST);
web_url("homeMoodInit.do","URL=http://apps.w.alisoft.com/apps/mood/homeMoodInit.do?jsoncallback=jsonp1247116589622&_=1247116589794",LAST);
web_url("poke!listPokeInfoForFriend.do","URL=http://apps.w.alisoft.com/apps/poke/poke!listPokeInfoForFriend.do?jsoncallback=jsonp1247116589624&_=1247116589825",LAST);
web_url("poke!listPokeInfoForNonFriend.do","URL=http://apps.w.alisoft.com/apps/poke/poke!listPokeInfoForNonFriend.do?jsoncallback=jsonp1247116589625&_=1247116589825",LAST);
web_url("poke!listPokeInfoForFriend.do","URL=http://apps.w.alisoft.com/apps/poke/poke!listPokeInfoForFriend.do?jsoncallback=jsonp1247116589626&_=1247116589825",LAST);
web_url("face.do","URL=http://apps.w.alisoft.com/apps/face/face.do?jsoncallback=jsonp1247116589627&_=1247116589903",LAST);
web_url("homePage!homePageMessages.do","URL=http://w.alisoft.com/space/home/homePage!homePageMessages.do?token=1247116589794",LAST);
web_url("firebug-lite-compressed.js","URL=http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js?_=1247116589872",LAST);
web_url("portal!feedList.do","URL=http://w.alisoft.com/space/feed/portal!feedList.do?token=1247116589809",LAST);
web_url("homePageFriendWidget.do","URL=http://w.alisoft.com/space/friend/homePageFriendWidget.do?token=1247116589794",LAST);
web_url("mullidstatus.aw","URL=http://amos.im.alisoft.com/mullidstatus.aw?beginnum=1&uids=",LAST);


用正则处理不大不小的文本是不是很爽?

附件是EditPlus的正则表达式帮助截图,想看就点开,最好自己下载一个玩玩。

[img]/upload/attachment/123427/d3a407b2-efd6-3a38-a49c-a46a983e691f.bmp[/img]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值