Skip to main content
Log in

Mojo package

regex

Regex module for pattern matching.

This module provides functionality for searching and matching patterns in strings using regular expressions. It implements a subset of regex features commonly found in other languages like Python, JavaScript, and Perl.

The module supports:

  • Pattern searching and matching with search(), match(), and fullmatch().
  • String splitting with split().
  • String substitution with sub().
  • Case-sensitive and case-insensitive matching.
  • Basic handling of escaped characters.

Example usage:

from stdlib.regex import search, match, sub

# Search for a pattern
if result = search("world", "hello world"):
print("Found at position:", result.value().start)

# Replace text
new_text = sub("hello", "hi", "hello world") # "hi world"
from stdlib.regex import search, match, sub

# Search for a pattern
if result = search("world", "hello world"):
print("Found at position:", result.value().start)

# Replace text
new_text = sub("hello", "hi", "hello world") # "hi world"

Modules

  • pattern_utils: Utility functions for regex pattern handling.
  • regex: Regular expression pattern matching implementation.