Character Classes
Character classes are a set of characters that match any one of the characters in the set.
Common character class escapes
const any: RegexConstruct;
const word: CharacterEscape;
const nonWord: CharacterEscape;
const digit: CharacterEscape;
const nonDigit: CharacterEscape;
const whitespace: CharacterEscape;
const nonWhitespace: CharacterEscape;
anymatches any character except newline characters. Regex syntax:..wordmatches any word character (letters, digits & underscore). Regex syntax:\w.nonWordmatches any character except word characters (letters, digits & underscore). Regex syntax:\W.digitmatches any digit. Regex syntax:\d.nonDigitmatches any character except digits. Regex syntax:\D.whitespacematches any whitespace character (spaces, tabs, line breaks). Regex syntax:\s.nonWhitespacematches any character except whitespace characters (spaces, tabs, line breaks). Regex syntax:\S.
anyOf()
function anyOf(characters: string): CharacterClass;
Regex syntax: [abc].
The anyOf class matches any character in the character string.
Example: anyOf('aeiou') will match either a, e, i o or u characters.
charRange()
function charRange(start: string, end: string): CharacterClass;
Regex syntax: [a-z].
The charRange class matches any characters in the range from start to end (inclusive).
Examples:
charRange('a', 'z')will match all lowercase characters fromatoz.charRange('A', 'Z')will match all uppercase characters fromAtoZ.charRange('0', '9')will match all digit characters from0to9.
charClass()
function charClass(...elements: CharacterClass[]): CharacterClass;
Regex syntax: [...].
The charClass construct creates a new character class that includes all passed character classes.
Examples:
charClass(charRange('a', 'f'), digit)will match all lowercase hex digits (0to9andatof).charClass(charRange('a', 'z'), digit, anyOf("._-"))will match any digit, lowercase Latin letter fromatoz, and either of.,_, and-characters.
negated()
function negated(element: CharacterClass): RegexConstruct;
Regex syntax: [^...].
The negated construct creates a new character class that matches any character not present in the passed character class.
Examples:
negated(digit)matches any character that is not a digitnegated(anyOf('aeiou'))matches any character that is not a lowercase vowel.