Regular Expression (basic)

Source: Internet
Author: User
1. The meta character of the regular expression: \ escape character. match a single character * match the first character (0) ^ match the followed regular expression, and match the regular expression at the beginning of the line $, the position at the end of the row [] matches the expression of any character \ {n, m \} in square brackets. The number of times that a single character matches before it \ {n \} indicates
1, Regular ExpressionMeta character of the expression:
\ Escape Character
. Match a single character
* Match the first character (> = 0)
^ Match followed Regular ExpressionAt the beginning of the row
$ Match the regular expression at the end of the row
[] Matching any character in square brackets
\ {N, m \} region expression, matching the number of times a single character is reproduced before it
\ {N \} indicates n times,
\ {N ,\} indicates at least n occurrences
\ {, M \} indicates a maximum of m occurrences
\ (\) Stores the mode between parentheses in a special reserved space, up to 9
Then, call in the same mode, such as \ (ac \). * \ 1.
Will find the achhehekehac string
\ N is usually used in combination with \ (\), 1 + Match one or more instances of the previous Regular Expression
? Matches zero or one instance of the previous regular expression.
| Match | regular expression before or after
() Regular expression group matching square brackets
2. POSIX character set:
[: LnUm:] numeric characters
[: Alpha:] letter
[: Blank:] space and tab)
[: Cn TrL:] control characters
[: Di Git:] Numeric characters
[: Graph:] non-space characters
[: Lower:] lowercase letter
[: Print:] printable characters
[: Pu NcT:] punctuation characters
[: Space:] blank characters
[: Upper:] uppercase characters
[: Xdigit:] hexadecimal number
3. Integration Grep CommandUsed to find the content required for selection according to the Regular Expression
Grep parameters:
-I is case insensitive.
-V returns an inverse value in the specified search result.
-N: displays the row number of the matched row in the file.
-An matches the first n rows of a row
-Bn matches the last n rows of a row
-Cn matches n rows before and after each row
-- ColOr highlighted
-E = EgrepExpand grep. Example: 1. See the specified string. You can see that the row of the specified aaa is selected, highlight 2. Select a line starting with a space. You can see that the line starting with a space is selected, that is, the fourth line. However, the color of the space is not displayed. You need to select a reversed line to see the color. 3. Select any string in the middle starting with aA, followed by the line ending with aA. 4. Select the line starting with a space and the aA line appears twice, there are other strings between the two aA. 5. You must select aA and aA will appear at a later position to show aA for multiple times and end with aA, for example: 6. Select the line 7 that starts with aAxy and ends with xyaA and display the-compliant character. The line appears three to six times again, as shown in the figure above, which is a basic regular expression, the following blog will introduce the extended regular expressions.

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.