栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

vim regex和普通regex有什么区别?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

vim regex和普通regex有什么区别?

如果用“正常正则表达式”来表示Perl兼容正则表达式(PCRE),那么Vim帮助就Vim的正则表达式和Perl的区别提供了一个很好的总结:

:help perl-patterns

从Vim 7.2开始,它是这样的:

9. Compare with Perl patterns     *perl-patterns*Vim's regexes are most similar to Perl's, in terms of what you can do.  Thedifference between them is mostly just notation;  here's a summary of wherethey differ:Capabilityin Vimspeak     in Perlspeak ~----------------------------------------------------------------force case insensitivity        c   (?i)force case sensitivity          C   (?-i)backref-less grouping%(atom)       (?:atom)conservative quantifiers        {-n,m}         *?, +?, ??, {}?0-width match        atom@=         (?=atom)0-width non-match    atom@!         (?!atom)0-width preceding match         atom@<=        (?<=atom)0-width preceding non-match     atom@<!        (?!atom)match without retry  atom@>         (?>atom)Vim and Perl handle newline characters inside a string a bit differently:In Perl, ^ and $ only match at the very beginning and end of the text,by default, but you can set the 'm' flag, which lets them match atembedded newlines as well.  You can also set the 's' flag, which causesa . to match newlines as well.  (Both these flags can be changed insidea pattern using the same syntax used for the i flag above, BTW.)On the other hand, Vim's ^ and $ always match at embedded newlines, andyou get two separate atoms, %^ and %$, which only match at the verystart and end of the text, respectively.  Vim solves the second problemby giving you the _ "modifier":  put it in front of a . or a characterclass, and they will match newlines as well.Finally, these constructs are unique to Perl:- execution of arbitrary pre in the regex:  (?{perl pre})- conditional expressions:  (?(condition)true-expr|false-expr)...and these are unique to Vim:- changing the magic-ness of a pattern:  v V m M   (very useful for avoiding backslashitis)- sequence of optionally matching atoms:  %[atoms]- & (which is to | what "and" is to "or";  it forces several branches   to match at one spot)- matching lines/columns by number:  %5l %5c %5v- setting the start and end of the match:  zs ze


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/412293.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号