Vim and grep regular expression similarities and differences

Source: Internet
Author: User
Tags grep regular expression

Regular expressions consist of two basic character types: literal (normal) text characters and metacharacters. Metacharacters enable regular expressions to have processing power. A meta-character is a special character in a regular expression that can be used to specify its leading character (that is, the character in front of the metacharacters) in the target object.
Vim Meta-character grep Meta-character Description
^ ^ Match the starting position of the input string
$ $ Match the starting position of the input string
* * Matches the preceding subexpression 0 or n times (n>0)
\+ \+ Matches the preceding subexpression 1 or n times (n>1)
\? \? Match previous subexpression 0 or 1 times
\{n}

\{n\}

Match determined N Times (n>=0)
\{n,} \{n,\} Minimum match n times (∞>n>=0)
\{N,M} \{n,m\} Match at least n times and up to M (n<m)
\< \< Match the first words of the word
\> \> Match word endings
| or characters, such as: X|y match x or Y
[ABC] [ABC] The character set is combined. Match any one of the characters contained
[^ABC] [^ABC] Represents any character that matches a character other than the characters in square brackets.
[A-z] [A-z] Character range, matching A-Z any character
[^a-z] [^a-z] Represents any character that matches a A-Z character except in square brackets.
\d ----------- Matches a numeric character. equivalent to [0-9]
\d ----------- Match non-numeric characters
\w \w Match 0-9,a-z,a-z
\w \w Match non-0-9,a-z,a-z

Vim and grep regular expressions are similar and different

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.