Regular expression notes
one。 Brief introduction:
A regular expression is basically a "representation", and as long as the tool program supports this representation, it can be used as a string processing of a regular expression. Tools such as vi,grep,awk,sed because they support regular expressions. A regular expression is an arrangement of special characters used to find, replace, and delete some or more lines of text strings. To put it simply, a regular expression is an "expression" used in string processing. It's really convenient to use it. So study hard.
two。 Basic type:
1. Character matching metacharacter:
. (period): matches any character
[]: matches one of the characters in parentheses
[^]: match other characters that do not include characters in parentheses
two。 Times match metacharacters:
*: match the previous characters any number of times (including zero)
\?: match the previous character zero or once (the preceding character is optional)
\ +: match the preceding characters at least once
\ {n\}: matches the preceding character n times
\ {n,\}: matches the preceding character at least n times
\ {, m\}: matches the preceding character at most m times (including zero times)
\ {NMagol m\}: matches the preceding character at least n times up to m times.
3. Position description metacharacter:
^: describe the beginning of the line
$: draw the end of the line
\
< (\b):描定词首(出现在表达式首部); \>(\ b): describe the suffix (appears at the end of the expression)
Grouping: used to store matching characters in memory variables for later reference.
\ (\): grouping symbol
\ 1: reference the character matched by the first group
4. Schedule:
Character
Description
\
Marks the next character as a special character, or a literal character, or a backward reference, or an octal escape character. For example,'n 'matches the character "n".' \ n' matches a newline character. The sequence'\ 'matches "\" and "(" matches "(".
^
Matches the starting position of the input string. If the Multiline property of the RegExp object is set, ^ also matches the position after'\ n'or'\ r'.
$
Matches the end position of the input string. If the Multiline property of the RegExp object is set, $also matches the position before'\ n'or'\ r'.
*
Matches the previous subexpression zero or more times. For example, zo* can match "z" and "zoo". * is equivalent to {0,}.
+
Matches the previous subexpression one or more times. For example, 'zo+' can match "zo" and "zoo", but not "z". + is equivalent to {1,}.
?
Matches the previous subexpression zero or once. For example, "do (es)?" Can match "do" in "do" or "does". ? It is equivalent to {0jue 1}.
{n}
N is a non-negative integer. Match the determined n times. For example,'o {2} 'does not match the' o'in 'Bob', but does match the two o in 'food'.
{n,}
N is a non-negative integer. Match at least n times. For example,'o {2,} 'does not match' o'in 'Bob', but does match all o in 'foooood'. O {1,}'is equivalent to 'oasis'. O {0,}'is equivalent to 'oval'.
{n,m}
M and n are non-negative integers, where n