Explanation of VIM Regular Expressions and their differences with Perl Regular Expressions

Source: Internet
Author: User
Tags arabic numbers printable characters

To use advanced search and replacement functions in Vim, you must be familiar with the regular expressions in Vim. Vim regular expressions are similar to the syntax of common regular expressions, but there are some differences.
Next we will introduce the vim Regular Expressions and point out their differences with Perl regular expressions.

Character Set

. Match any character \ W to match the letter, which is equivalent to [0-9a-za-z _]. \ W matches any character other than the letter, which is equivalent to [^ 0-9a-za-z _]. \ T matching characters. \ A all letter characters. equivalent to [A-Za-Z] \ e \ t \ r \ B \ D number [0-9] \ D non-digit [^ 0-9] \ x hexadecimal number [0-9a-fa-f] \ x non-hexadecimal number [^ 0-9a-fa-f] \ s blank character [] (and ), equivalent to [/T] \ s non-blank character [^] (except for sum ), equivalent to [^/T] \ L lowercase letter [A-Z] \ L non-lowercase letter [^ A-Z] \ U uppercase letter [A-Z] \ U non-capital letter [^ A-Z] \ I identifier character 'isident' \ I is the same as \ I, however, the numbers \ K keyword characters \ K and \ K are excluded, but the numbers \ P printable characters \ P and \ P are excluded, but the numbers \ f file name characters \ f and \ f are excluded, however, excluding numbers \ _ indicates a segment line, which is a combination of the above characters, such as \ _ s and \ _...

Range

[ABC] matches any character in square brackets. You can use-to indicate a range of characters. [a-z0-9] matches lowercase letters and Arabic numbers. [^ ABC] starts with square brackets and uses the ^ symbol to match any character other than the characters in square brackets.

Select one more

The "or" operator in the mode is "\ | ". For example,/Foo \ | bar

Group
\(\)
You can use \ 1, \ 2, and... To reference the content captured \ (\).
Perl :()

Quantity (repeated times)

* Matches 0-any * \ {-\} *'s inert mode Perl :*? \ + Matches 1 to any Perl: + \ {-\} \ +'s inert mode Perl: +? \? Matches 0-1 Perl :? \ {N, m \} matches N-M Perl: {n, m} \ {-n, m \} \ {n, m \}'s inert mode Perl: {n, m }? \ {N \} matches n Perl: {n} \ {-n \} \ {n \}'s inert mode Perl: {n }? \ {N ,\} matches n to any Perl: {n ,}\{-N ,\}\{ n ,\} in the inert Perl :{ n ,}? \ {, M \} matches 0-M Perl: {0, m}
Metacharacter description \ * match * character \. Match. Character \/match/character \ match \ character \ [Match [Character

Location

$ Match the end of a line ^ match the beginning of a line \ <match the beginning of a word Perl: \ B \> match the end of a word

Function Type
: S/replace string // = Function Type
In the function formula, submatch (1) and submatch (2) can be used to reference content such as/1 and/2, while submatch (0) can reference the entire Matching content.

This entry was written by zpz, posted on 2012
June 30 at pm, Filed under Linux, VIM and
Tagged vim, VIM Regexp, VIM tutorial, VIM replacement, VIM regular, regular expression.
Bookmark the permalink. follow any comments here with the RSS
Feed for this post. post a comment or leave a trackback: trackback
URL.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.