Loading

Emacs正则表达式+零宽断言/环视

2013/6/3 追记:文中介绍的方法需要编译,太麻烦,我已上传编译好的Emacs 24.2(Windows版),请访问下面链接,点“regex-lookaround”下载:https://github.com/gamesun/emacs/tags

 

环视(Lookaround)或者叫作前向/后向零宽断言,其介绍可以看这里:Lookahead and Lookbehind Zero-Width Assertions

在GNU Emacs的正式发行版中,正则表达式对环视是不支持的,幸好有一个叫松山朋洋(Tomohiro Matsuyama)的高手帮忙解决了这个问题。(原帖:http://emacs.1067599.n5.nabble.com/Patch-for-lookaround-assertion-in-regexp-td121057.html#a23863009

可惜是三年前的帖子,对于现在的Emacs24.2版本有点出入,打补丁时会FAILED,并有一个编译错误。我对其做了点调整,补丁文件点这里下载或者访问这里获取https://github.com/gamesun/emacs-regex-lookaround

然后使用如下命令合并到Emacs源码:

cd emacs
patch -b -p0 < ../emacs-24.2-regex.patch

然后请参考编译Emacs for Windows,进行编译就可以了。

在24.2版本上测试通过,效果如下:

image

 

posted @ 2013-02-05 20:30  gamesun  阅读(1797)  评论(0编辑  收藏  举报