Vim and Regular Expression: what kind of regex does Vim use?
开发者_如何学CSince 6 months I'm using the excellent Vim text-editor. The most interesting thing is Vim's excellent regex support build-in.
I would like to understand regex better in order to ask less questions here :)
I tried Regex coach, Espresso and other regex-help applications but I found out that even if they are working in these applications it often doesn't work in VIM. What kind of regex does Vim use? Are there any help applications in which I can build regex commands for Vim?
As far as I know vim
uses it's own flavor. Here is what the manual says:
Vim's regexes are most similar to Perl's, in terms of what you can do. The difference between them is mostly just notation;
If you want a better (more serious) explanation, look up "Traditional NFA" in Mastering Regular Expressions.
Vim has several regex modes, one of which is very magic
that's very similar to traditional regex. Just put \v
in the front and you won't have to escape as much.
There is a plugin called eregex.vim which translates from PCRE (Perl-compatible regular expressions) to Vim's regex syntax.
This will make it more likely for regexes from other environments to work, because PCRE have become the de facto industry standard: e.g. Java's java.util.regex
, Python's re
module, and regexes found in Ruby and JavaScript are all PCREs (each with slight differences).
精彩评论