Skip to main content
Log in

Mojo function

get_common_character_classes

get_common_character_classes() -> Dict[String, CharacterClass]

Get a dictionary of common character classes used in regex.

This function creates and returns a dictionary containing the standard character classes used in regular expressions. Each character class is mapped from its regex syntax representation (like "\d" for digits) to a CharacterClass object containing all the characters in that class.

The following character classes are included:

  • \d: Digits (0-9).
  • \w: Word characters (letters, digits, underscore).
  • \s: Whitespace characters (space, tab, newline, etc.).
  • \D: Non-digits (complement of \d).
  • \W: Non-word characters (complement of \w).
  • \S: Non-whitespace (complement of \s).

These character classes correspond to the standard character classes used in most regex engines like PCRE, Python's re module, and JavaScript.

The returned dictionary can be used to quickly look up a character class by its syntax representation and get the corresponding set of characters.

Returns:

A dictionary mapping regex character class syntax (like "\d") to CharacterClass objects containing the appropriate characters.