Support for regular expressions (RE).
支持正则表达式(RE)。
This module provides regular expression matching operations similar to those found in Perl.
It supports both 8-bit and Unicode strings; both the pattern and the strings being processed can contain null bytes and characters outside the US ASCII range.
这个模块提供了类似于Perl中的正则表达式匹配操作。
它支持8位和Unicode字符串;正在处理的模式和字符串都可以包含空字节和超出美国ASCII范围的字符。
Regular expressions can contain both special and ordinary characters.
Most ordinary characters, like "A", "a", or "O", are the simplest regular expressions; they simply match themselves.
You can concatenate ordinary characters, so last matches the string 'last'.
正则表达式可以包含特殊字符和普通字符。
大多数普通字符,如“A”、“A”或“O”,都是最简单的正则表达式;他们只是匹配自己。
您可以连接普通字符,因此last匹配字符串'last'。
1 特殊字符 The special characters are:
"." Matches any character except a newline.
"^" Matches the start of the string.
"$" Matches the end of the string or just before the newline at
the end of the string.
"*" Matches 0 or more (greedy) repetitions of the preceding RE.
Greedy means that it will match as many repetitions as possible.
"+" Matches 1 or more (greedy) repetitions of the preceding RE.
"?" Matches 0 or 1 (greedy) of the preceding RE.
*?,+?,?? Non-greedy versions of the previous three special characters.
{m,n} Matches from m to n repetitions of the preceding RE.
{m,n}? Non-greedy version of the above.
"\\" Either escapes special characters or signals a special sequence.
[] Indicates a set of characters.
A "^" as the first character indicates a complementing set.
"|" A|B, creates an RE that will match either A or B.
(...) Matches the RE inside the parentheses.
The contents can be retrieved or matched later in the string.
(?aiLmsux) Set the A, I, L, M, S, U, or X flag for the RE (see below).
(?:...) Non-grouping version of regular parentheses.
(?P<name>...) The substring matched by the group is accessible by name.
(?P=name) Matches the text matched earlier by the group named name.
(?#...) A comment; ignored.
(?=...) Matches if ... matches next, but doesn't consume the string.
(?!...) Matches if ... doesn't match next.
(?<=...) Matches if preceded by ... (must be fixed length).
(?<!...) Matches if not preceded by ... (must be fixed length).
(?(id/name)yes|no) Matches yes pattern if the group with id/name matched,
the (optional) no pattern otherwise.
"." Matches any character except a newline. 匹配除换行符以外的任何字符。 "^" Matches the start of the string. 匹配字符串的开头。 "$" Matches the end of the string or just before the newline at the end of the string. 匹配字符串的末尾或字符串末尾换行符之前。 "*" Matches 0 or more (greedy) repetitions of the preceding RE. Greedy means that it will match as many repetitions as possible. "+" Matches 1 or more (greedy) repetitions of the preceding RE. 匹配前一个正则的1个或多个(贪婪)重复。 "?" Matches 0 or 1 (greedy) of the preceding RE. 匹配前一个正则的0或1(贪婪)。 *?,+?,?? Non-greedy versions of the previous three special characters. 前三个特殊字符的非贪婪版本。 {m,n} Matches from m to n repetitions of the preceding RE. {m,n}? Non-greedy version of the above. "\\" Either escapes special characters or signals a special sequence. [] Indicates a set of characters. A "^" as the first character indicates a complementing set. "|" A|B, creates an RE that will match either A or B. A|B,创建一个匹配A或B的正则。 (...) Matches the RE inside the parentheses. The contents can be retrieved or matched later in the string. (?aiLmsux) Set the A, I, L, M, S, U, or X flag for the RE (see below). (?:...) Non-grouping version of regular parentheses. (?P<name>...) The substring matched by the group is accessible by name. (?P=name) Matches the text matched earlier by the group named name. (?#...) A comment; ignored. (?=...) Matches if ... matches next, but doesn't consume the string. (?!...) Matches if ... doesn't match next. (?<=...) Matches if preceded by ...