Regular Expression note

Source: Internet
Author: User
Tags class operator comparison table printable characters expression engine

The translation I translated from gun manual is a little poor, but I can understand it easily. In fact, laruence's Private food contains part of the content of 90% in GNU manual, for more information, see laruence Linux cainiao.

 

Match dictionary letters
The dot (.) matches any character other than line breaks and null, for example, 'a. B 'matches a string of three characters starting with a and ending with B.
After B is followed by a, the result is a regular expression that matches a string. If a matches the second part, B matches the second part.

Repeated operators '*', '+ ','? '
* Matches zero or zero times. 'fo' matches 'F', 'fo', and 'foo '.
+ Match one or more times
? Matches zero times or once

Interval operator {} Or /{/}
{Count} matches the exact count times with the words in the previous regular expression.
{Min,} matches words that match the Regular Expression in minutes or more times.
{Min, max} matches at least min times, but no more than Max times meet the previous regular expression word
The following situations are invalid:
1. Min is greater than Max
2. Any count, Max, and Min values outside 0 and're _ dup_max'

Select operator |
Any condition in the expression will be matched to 'foo | bar | quux ', such as 'foo', 'bar', or 'quux'

List operator []
Match one of the characters listed in brackets, such as [AB], to match A or B
The mismatch list is given by "[^ character]", for example, [^ AB] matches all characters except a and B.
The characters in brackets are called lists. special characters in the list have different meanings. If ']' appears, escape
'[:' Indicates the start character class operator. If're _ char_classes 'is set, a valid character class expression is followed.
':]' Indicates the operator of the closed character class. If're _ char_classes 'is set, the start character operator before it is formed by the operator of the valid character class plus the end character operator.
'-' Indicates the range operator.
All other characters are dictionary characters (not escaped) such as '[. *]' matching. And '*'
Note: '^' is not the starting character in the list.

Character class operator [:]
If the semantic bit're _ character_classes 'is set, the Regular Expression Engine can recognize the character class expressions in the list.
Format: [: Class-Name:]
The character class name and its meaning are as follows:
Alnum letters and numbers
Alpha letter
Blank system related. GNU system, a space or a tab
Cntrl control character, ASCII code, code value 0177 and code value less than 040
Digit numbers
The graph and print are the same except for spaces.
Lower-case lower letters
Print printable characters, ASCII encoding, space, waveform symbol-code value: 040 to 0176
Punct is neither a control nor a letter character
Space press enter, line feed, vertical tab, form feed
Upper case letters
Xdigit hexadecimal number

Range operator '-'
The range expression in the Regular Expression Engine recognition list (list), for example, [A-F], indicates the character ranges including A and F.
If re_no_empty_ranges is set, it is invalid if the sequence of the start point table is greater than the end point, for example, [Z-A]. If this bit is not set, the expression considers this interval to be null.
A. if you want to use '-' in the list, place it at the beginning or end of the list.
B. contains a range so that the actual vertex comparison table is smaller than '-', and its ending point is equal to or greater than '-', unless a range is the first element in the list, otherwise, '-' cannot be its starting point, but can be its ending point. This is because the regular engine treats '-' as an interval operator unless it has another '-' (include a range whose starting point collates strictly lower than '-' and whose ending point collates equal or higher. unless a range is the first item in a list, a'-'Can't be its starting point, but _ Can _ be its ending point. that is because RegEx considers '-' to be the range operator unless it is preceded by another '-'.)
For example, in the ASCII code, ')', '*', '+ ',',','-','. the ','/'character is a continuous character (in the ABCD format) in the sequence table, for example,' [)-+ --/] 'interval ') -+ 'and' + -- 'plus the character'/', not')-+'
And '--/'.
C. Place the range operator '-' in the first element of the list,
For example, '[-a-Z]' matches lowercase letters or a font size.

Grouping operator ()
Grouping operators are called subexpressions. Regular Expressions regard the sequence in parentheses together with parentheses as a unit.
You can use groups:
A. delimit the argument (s) to an alternation operator or a repetition operator
B. Keep track of the indices of the substring that matched a given
Group.

Post-reference operator (the escape character we often call )/
N

Positioning Operator
'^' Matches the first line operator
'$' Matches the end operator.

GNU Operator
'/B' word boundary matching Operator
'/B' intra-word matching Operator
'/<' Start matching Operator
'/>' End matching Operator
'/W' match-word-constituent operato
'/W' match-non-word-constituent OPERATOR:

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.