bobzhang/pygments/regex does not have a README file

    RegexError

    pub suberror RegexError {
    Syntax(pattern~ : String, pos~ : Int, message~ : String)
    BudgetExceeded(pattern~ : String)
    } derive(
    Debug
    )

    Errors raised by the regex engine.

    Budget

    pub struct Budget {
    remaining : Int
    }

    A step budget shared by several match calls (e.g. one lexing request).

    Budget::new

    fn Budget::new(steps : Int) -> Budget

    Creates a budget of steps VM steps.

    Match

    pub struct Match {
    text : String
    // private fields
    }

    The result of a successful match.

    Match::end

    fn Match::end(self : Match, group? : Int) -> Int

    End offset of group g (default 0), or -1 if it did not participate.

    Match::from_span

    fn Match::from_span(text : String, start : Int, end : Int) -> Match

    A match object covering text[start:end] with no groups (Python's _PseudoMatch, used when a callback is applied to a sub-group).

    Match::group

    fn Match::group(self : Match, g : Int) -> String?

    Text of group g, or None if it did not participate.

    Match::group_count

    fn Match::group_count(self : Match) -> Int

    Number of capturing groups of the pattern.

    Match::matched

    fn Match::matched(self : Match) -> String

    Text of the whole match.

    Match::name_index

    fn Match::name_index(self : Match, name : String) -> Int?

    Index of the named group name.

    Match::named

    fn Match::named(self : Match, name : String) -> String?

    Text of the named group name, if it exists and participated.

    Match::start

    fn Match::start(self : Match, group? : Int) -> Int

    Start offset of group g (default 0), or -1 if it did not participate.

    Regex

    pub struct Regex {
    pattern : String
    flags : Int
    // private fields
    }

    A compiled regular expression with Python re syntax and semantics, matching code points over a UTF-16 String. Positions are UTF-16 offsets.

    Regex::find_all

    fn Regex::find_all(self : Regex, text : String, budget? : Budget) -> Array[Match] raise RegexError

    All non-overlapping matches, like Python's finditer (an empty match may be followed by a non-empty match at the same position).

    Regex::fullmatch

    fn Regex::fullmatch(self : Regex, text : String, pos? : Int, endpos? : Int, budget? : Budget) -> Match? raise RegexError

    Python's pattern.fullmatch(text, pos, endpos).

    Regex::group_count

    fn Regex::group_count(self : Regex) -> Int

    Number of capturing groups.

    Regex::group_index

    fn Regex::group_index(self : Regex, name : String) -> Int?

    Index of the named group name.

    Regex::match_at

    fn Regex::match_at(self : Regex, text : String, pos : Int, endpos? : Int, budget? : Budget) -> Match? raise RegexError

    Python's pattern.match(text, pos, endpos): matches only at pos.

    Regex::replace_all

    fn Regex::replace_all(self : Regex, text : String, f : (Match) -> String, budget? : Budget) -> String raise RegexError

    Replaces every match with the result of f (Python's sub with a function).

    Regex::search

    fn Regex::search(self : Regex, text : String, pos? : Int, endpos? : Int, budget? : Budget) -> Match? raise RegexError

    Python's pattern.search(text, pos, endpos). One budget covers the whole scan.

    Regex::split

    fn Regex::split(self : Regex, text : String, budget? : Budget) -> Array[String?] raise RegexError

    Python's pattern.split(text) (captured groups are included).

    ASCII

    let ASCII : Int

    re.ASCII

    DOTALL

    let DOTALL : Int

    re.DOTALL

    IGNORECASE

    let IGNORECASE : Int

    re.IGNORECASE

    LOCALE

    let LOCALE : Int

    re.LOCALE (accepted, treated as no-op)

    MULTILINE

    let MULTILINE : Int

    re.MULTILINE

    UNICODE

    let UNICODE : Int

    re.UNICODE (the default for text patterns)

    VERBOSE

    let VERBOSE : Int

    re.VERBOSE

    compile

    fn compile(pattern : String, flags? : Int) -> Regex raise RegexError

    Compiles pattern with Python re flags (IGNORECASE, MULTILINE, ...).

    test {
    let re = @regex.compile("(?P<word>\\w+)\\s*=", flags=@regex.MULTILINE)
    guard re.match_at(" key = 1", 2) is Some(m) else { fail("no match") }
    debug_inspect(m.group(1), content="Some(\"key\")")
    inspect(m.end(), content="7")
    }

    default_steps

    let default_steps : Int

    Default number of VM steps allowed for a single match call without an explicit budget.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io