Literals¶
Literals are the simplest form of pattern matching in regular expressions. They will simply succeed whenever that literal is found.
.anyChar¶
Matches any character except a newline.
Example
ExpressiveRegex()\
.anyChar\
.toRegexString()
"."
.whitespaceChar¶
Matches any whitespace character; equivalent to [ \t\n\r\f\v].
In Unicode it will match the whole range of Unicode whitespace characters.
Example
ExpressiveRegex()\
.whitespaceChar\
.toRegexString()
"\s"
.nonWhitespaceChar¶
Matches any non-whitespace character; equivalent to [^\s].
Example
ExpressiveRegex()\
.nonWhitespaceChar\
.toRegexString()
"\S"
.digit¶
Matches any non-whitespace character; equivalent to [0-9].
In Unicode it will match the whole range of Unicode digits.
Example
ExpressiveRegex()\
.digit\
.toRegexString()
"\d"
.nonDigit¶
Matches any non-digit character; equivalent to [^\d].
Example
ExpressiveRegex()\
.nonDigit\
.toRegexString()
"\D"
.word¶
Matches any alpha-numeric (a-z, A-Z, 0-9) characters, as well as _.
In Unicode it will match the range of Unicode alphanumeric characters
(letters plus digits plus underscore).
Example
ExpressiveRegex()\
.word\
.toRegexString()
"\w"
.nonWord¶
Matches any non alpha-numeric (a-z, A-Z, 0-9) characters, excluding _ as well.
Example
ExpressiveRegex()\
.nonWord\
.toRegexString()
"\W"
.newline¶
Matches a \n character.
Example
ExpressiveRegex()\
.newline\
.toRegexString()
"\n"
.carriageReturn¶
Matches a \r character.
Example
ExpressiveRegex()\
.carriageReturn\
.toRegexString()
"\r"
.tab¶
Matches a \t character.
Example
ExpressiveRegex()\
.tab\
.toRegexString()
"\t"
.space¶
Matches a character.
Example
ExpressiveRegex()\
.space\
.toRegexString()
" "
.char(c)¶
Matches the exact char c but scape special characters ('\', '.', '^', '$', '|', '?', '*', '+', '(', ')', '[', ']', '{', '}', '-').
Examples
ExpressiveRegex()\
.char('a')\
.toRegexString()
"a"
ExpressiveRegex()\
.char('$')\
.toRegexString()
"\$"
.rawChar(c)¶
Matches the exact char c and don't scape special characters.
Examples
ExpressiveRegex()\
.rawChar('a')\
.toRegexString()
"a"
ExpressiveRegex()\
.rawChar('$')\
.toRegexString()
"$"
.string(s)¶
Matches the exact string s but scape special characters ('\', '.', '^', '$', '|', '?', '*', '+', '(', ')', '[', ']', '{', '}', '-').
Example
ExpressiveRegex()\
.string('2$')\
.toRegexString()
"2\$"
.rawString(s)¶
Matches the exact string s and don't scape special characters.
Example
ExpressiveRegex()\
.string('2$')\
.toRegexString()
"2$"
.range(a, b, exclude)¶
Matches any character that falls between a and b and don't mathch character
in the exclude set. a and b must be same type, a<=b and:
- if
"a"<=a<="z"then"a"<=b<="z" - if
"A"<=a<="Z"then"A"<=b<="A" - if
"0"<=a<="9"then"0"<=b<="9" - if
0<=a<=9then0<=b<=9
exclude must be an string or list or tuple of single char string. By default exclude is None
Examples
ExpressiveRegex()\
.range('a','f')\
.toRegexString()
"[a-f]"
ExpressiveRegex()\
.range('a','f', exclude='bd')\
.toRegexString()
"[acef]"
ExpressiveRegex()\
.range('a','f', exclude=['b','d'])\
.toRegexString()
"[acef]"
.anythingButRange(a, b, exclude)¶
Matches any character, except those that would be captured by the .range.
Examples
ExpressiveRegex()\
.anythingButRange('a','f')\
.toRegexString()
"[^a-f]"
ExpressiveRegex()\
.anythingButRange('a','f', exclude='bd')\
.toRegexString()
"[^acef]"
.anyOfChars(chars)¶
Matches any of the characters in the provided string chars and scape special characters.
Example
ExpressiveRegex()\
.anyOfChars('abd$')\
.toRegexString()
"[abd\$]"
.anythingButChars(chars)¶
Matches any character, except any of those in the provided string chars and scape special characters.
Example
ExpressiveRegex()\
.anythingButChars('abd$')\
.toRegexString()
"[^abd\$]"