Vim must learn well and understand the regular expression)

Source: Internet
Author: User

This article is well organized on the Internet, and its form is as follows:

Formal expression Description and Examples Unmatched strings
// String containing the letter "A", such as "AB", "BAC", and "CBA" "Xyz"
/./ A string containing the letter "A" and any subsequent characters, such as "AB" and "BAC" (use \.) "A", "BA"
/^ XY/ A string starting with "XY", such as "XYZ" and "xyab" (use \ ^ To compare to ^) "Callback", "bxy"
/XY $/ String ending with "XY", for example, a string ending with "XY", a string ending with "XY", for example, "Callback ", "abxy" (if you want to compare $, use \ $) "Xya", "xyb"
[13579] A string containing "1", "3", "5", "7", or "9", for example, "a3b" and "1xy" "Y2K"
[0-9] String containing numbers String without data
A-z0-9 String containing numbers or letters String without numbers and small numbers
A-zA-Z0-9 String containing numbers or letters String without numbers and letters
B [aeiou] T "Bat", "bet", "bit", "BOT", "" "Bxt", "bzt"
[^ 0-9] String without data (use \ ^ for comparison ^) String containing numbers
[^ Aeiouaeiou] A string without the mother tone (use \ ^ for comparison ^) Audio-containing string
[^ \ ^] It does not contain "^" strings, such as "XYZ" and "ABC" "XY ^", "a ^ BC"

.

Specific characters of the Regular Expression Description Equivalent positive expression
\ D Data [0-9]
\ D Non-numeric characters [^ 0-9]
\ W Number, letter, base character [A-zA-Z0-9 _]
\ W Non \ W [^ A-zA-Z0-9 _]
\ S Blank character [\ R \ t \ n \ F]
\ S Non-blank characters [^ \ R \ t \ n \ F]

.

Formal expression Description
/? / Zero or one A (If yes? Character, use \?)
/A +/ One or more A (use \ + for comparison to + characters)
/*/ Zero or more A characters (use \ * If You Want To match * characters \*)
/A {4 }/ Four
/A {5, 10 }/ Five to ten
/A {5 ,}/ At least five
/A {, 3 }/ Up to three
/A. {5} B/ Five (non-linear) characters in A and B

.

Character Description Simple Example
\ Escape special characters /A \ */Applicable to comparison with "A *", where * is a special character. To avoid its special meaning, you must add "\"
^ The starting position of the primary Column /^ A/comparable to "a" in "ABCD", but not comparable to "AAB"
$ Compare the end position of the limit Column /A $/comparable to "a" in "BCDA", but not comparable to "AAB"
* Zero or more times than the previous character /Bo */comparable to "booo" in "good boook" or "B" in "good BK"
+ Equivalent to {1 ,} /A +/comparable to "AAA" in "caaandy", but not comparable to "cndy"
? Zero or one time than the previous character /E? L/comparable to "EL" in "Angel", it can also be compared to "L" in "angle"
. Compared to any character (but the Delimiter is not counted) /. N/comparable to "an" and "on" in "Nay, an apple is on the tree", but not comparable to "nay"
(X) Compare to X and store the matching part into a variable /(A *) and (B *)/comparable to "AAA" and "BB" in "AAA and BB ", set the two pairs to Regexp. $1 and Regexp. $2.
XY Comparison with X or Y /A * B */g can compare "AAA" and "BB" in "AAA and BB"
{N} Compared to the previous CHARACTER n times, n is a positive integer /A {3}/comparable to "AAA" in "lllaaalaa", but not "AA"
{N ,} Compared to the previous character for at least N times, n is a positive number /A {3,}/comparable to "AAA" and "AAAA" in "aa aaa aaaa", but not "AA"
{N, m} The ratio is positive for at least N times and at most m times for the previous character. /A {3, 4}/comparable to "AAA" and "aaaa" in "aa aaa aaaaa", but not comparable to "AA" and "AAAAA"
[Xyz] Compared to any character in the ARC /[ECM]/comparable to "E", "C", or "M" in "welcome"
[^ XYZ] Compared to any character that does not exist in the ARC /[^ ECM]/the opposite of [xyz] for "W", "L", and "O" in "welcome. (Note the difference between the functions of/^/and [^] at the same time .)
[\ B] Backspace character) The difference between [\ B] and \ B can be better than that of a backspace.
\ B Comparison with English text, such as spaces For example,/\ bn \ W/can be compared to 'no' in "noonday ';
/\ WY \ B/comparable to 'ly 'in "possibly yesterday'
\ B Comparison with non-English text 」 For example,/\ W \ BN/can be compared to 'on' in "noonday ',
In addition,/Y \ B \ W/can be compared to 'day' in "possibly yesterday'
\ CX Control Character, where X is a control character /\ Cm/can be compared to control-m in a string
\ D Equivalent to [0-9] /[\ D]/comparable to any number of words from "0" to "9", but their names, such as letters, are not comparable
\ D Equivalent to [^ 0-9] /[\ D]/comparable to "W" ""... However, it is not comparable to a number such as "7" and "1 ".
\ F Comparison with form-feed If there is a line in the text that produces "success", the comparison can be successful.
\ N Comparison with the delimiter If there is a line with "success" in the text, the comparison can be successful.
\ R Returns  
\ S Equivalent to [\ f \ n \ r \ t \ v] /\ S \ W */comparable to "B" in "a B"
\ S For any non-blank character, it is equivalent to [^ \ f \ n \ r \ t \ v] /\ S/\ W * is comparable to "a" in "a B"
\ T Comparison Between Positioning characters (Tab)  
\ V Vertical Tab)  
\ W Equivalent to [A-Za-z0-9 _] /\ W/comparable to ". _! "A", "_", and "9" in "9 ″.
\ W Equivalent to [^ A-Za-z0-9 _] /\ W/comparable to ". _! ".", "", "!" In 9 ", It can be seen that the function is opposite to/\ W.
\ OOctal Comparison with the eight-in-one, of whichOctalIt is an octal number. /\ Oocetal123/compares the character value corresponding to "123" in the ASCII code with the octal.
\ XHEX Compare to the hexadecimal position, whereHEXIs the hexadecimal number /\ Xhex38/can be equivalent to the character corresponding to "38" in the ASCII code that matches the hexadecimal value.

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.