Character classes represented by regular expression syntax | ||
Examples | of characters matched by | the character class |
dNumbers | from 0 to 9 | dd can match 72, but cannot match 7a or a7 |
DNon-digit characters | DDD can match a%c, but cannot match 123 | |
wUnderscores and word characters | wwwcan match a2_, but not x&a | |
WNon-word characters and non-underscores | WWcan match &^, but not a1 | |
sWhite | space characters, including tabs character, line feed, carriage return, form feed and vertical tab | |
S | non-whitespace character | |
.any | character | |
[...] | Any character within brackets | [abc] matches a single character a, b, or c, but not other characters [az] matches any character from a to z |
[^...] | Any character not within brackets | [ ^abc] matches any character except a, b, c [az] matches any character other than a~z, but matches large letters |
Positioning character | ||
Positioning character | description | |
^ | The pattern that follows must be at the beginning of the string. If it is a multi-line string, it should be at the beginning of any line. For multiline text, you need to set the multiline flag | |
$ | The preceding pattern must be at the end of the string. If it is a multiline string, it should be at the end of any line | |
AThe | preceding pattern must be at the beginning of the string; The multi-line flag is ignored | |
zThe | preceding pattern must be at the end of the string; the multi-line flag is ignored | |
ZThe | preceding pattern must be at the end of the string; or before a newline character | |
bMatches | a word boundary, referring to the above is the point between word characters and non-word characters. Word characters are any characters in [a-zA-Z0-9]. at the beginning of a word | |
B | matches a position other than this boundary, not the beginning of a word | |
Basic repeating characters | ||
Examples | ofrepeated character | meanings |
{n} | matches the previous character n times | x{2} matches xx, but does not match x, or xxx |
{n,} | matches the previous character n times or more | x{2,} matches xx or xxx and More x, |
{n,m} | matches the previous character at least n times and at most m times. | x{2,4} matches xx, xxx, xxxx but does not match x, or xxxxx |
? | Matches the previous character 0 or 1 times. | x? Match x or null |
+ | match the previous character 1 or more times | x + match x or the same |
* | match the previous character 0 or | more |
times |