Introduction:
Regular Expressions are widely used in the field of word processing. To learn regular expressions, the most important thing is the sequence of learning, from simple concepts to complex concepts.
Basic Syntax:
Deelx supports the basic syntax of Perl-Compatible Regular Expressions. The basic syntax rules are basically the same in different regular expressions.
1. common characters
Letters, numbers, Chinese characters, underscores, and punctuation marks that are not defined with special meanings are all "common characters ".
2. Simple escape characters
Characters that cannot be written, such as line breaks and tabs, are represented by \ n and \ t. In addition, some punctuation marks are defined in regular expressions with special meanings. Therefore, you must add"\"After escaping, match the character itself.
Escape Character \ Q... \ e
Start with \ q and end with \ e. the punctuation marks in the middle are meaningless and the characters in the middle are used as common characters.
Start with \ U and end with \ e. Besides having the same functions as \ Q... \ e, the lowercase letters in the middle are also converted into uppercase letters. In case-sensitive mode, it can only match uppercase text.
Start with \ L and end with \ e. Besides having the same functions as \ Q... \ e, uppercase letters in the middle are also converted to lowercase letters. In case-sensitive mode, it can only match lower-case text.
Note: \ Q... \ e is suitable for: the expression requires long plain text, which contains special symbols.
For example:
\ Q (a + B) * 3 \ e (a + B) * 3 <=> \ (A \ + \ B) \ * 3
3. Character Set combination
A regular expression that matches any one of the "multiple characters. Although it is "multiple characters", only one of them can be matched at a time.
Custom Character Set combination:
It can contain multiple characters in brackets [] and can match any of the characters in it. Similarly, only one of them can be matched at a time.
The brackets [^] contain multiple characters to form a negative format. It can match any character other than the included characters.
4. The matching frequency qualifier
Make the modified expression repeat the modifier for multiple times.
If the expressions after the qualifier can match successfully, the indefinite number of delimiters always match as many as possible. If the subsequent expression fails to match, the qualifier can properly "give up" the matching characters to make the entire expression match successfully. This mode is called"Greedy mode".
5. Character Boundary
It does not match any character, and only adds a conditional expression to the character boundary and the gap between characters.
^ The current position must start with the text
$ The current position must be the end position of the text
\ B the left and right sides of the current position. Only one side can contain letters, numbers, and underscores.
6. Select an expression
Use vertical bars"|"Separates multiple expressions. The entire expression can match any part of the expression.
Note:
The Regular Expression Engine always tries to match from left to right. If each expression fails to match, the entire expression fails to match.
7. Group
Brackets()When other expressions are included, the contained expressions can form a whole. When the number of matching times is modified, they can be modified as a whole.
In addition, the matching content will be recorded separately using the expressions in parentheses, which can be obtained during or after the matching process.
Description
Each pair of parentheses is assigned a number, and the number starts from 1 in the order of the left parentheses. The first capture of zero element number is text that is matched by the entire regular expression pattern.
Basic regular expression syntax