Sign in

    bobzhang/asciidoctor/regex does not have a README file

    RegexError

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

    Error raised when a pattern cannot be compiled.

    MatchData

    pub struct MatchData {
    input : String
    // private fields
    }

    Result of a successful match.

    MatchData::at

    fn MatchData::at(self : MatchData, i : Int) -> String

    Captured text of group i, or "" if it did not participate.

    MatchData::begin

    fn MatchData::begin(self : MatchData, i? : Int) -> Int

    Start offset of group i (-1 if unset).

    MatchData::end

    fn MatchData::end(self : MatchData, i? : Int) -> Int

    End offset of group i (-1 if unset).

    MatchData::expand

    fn MatchData::expand(self : MatchData, template : String) -> String

    Expands a Ruby replacement template: \0/\&, \1..\9, \k<name>, \` , \', \\.

    MatchData::group

    fn MatchData::group(self : MatchData, i : Int) -> String?

    Captured text of group i (0 = whole match), or None if the group did not participate.

    MatchData::groups

    fn MatchData::groups(self : MatchData) -> Array[String?]

    All groups (including group 0) as optional strings.

    MatchData::has

    fn MatchData::has(self : MatchData, i : Int) -> Bool

    Whether group i participated in the match.

    MatchData::has_names

    fn MatchData::has_names(self : MatchData) -> Bool

    Whether the pattern has named groups.

    MatchData::matched

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

    The whole matched text.

    MatchData::named

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

    Text of a named group.

    MatchData::post_match

    fn MatchData::post_match(self : MatchData) -> String

    Text after the match.

    MatchData::pre_match

    fn MatchData::pre_match(self : MatchData) -> String

    Text before the match.

    MatchData::size

    fn MatchData::size(self : MatchData) -> Int

    Number of groups including group 0.

    Regex

    pub struct Regex {
    source : String
    // private fields
    }

    A compiled regular expression using Ruby (Onigmo) syntax and semantics, operating on UTF-16 strings with absolute code-unit offsets.

    Semantics follow Ruby: ^/$ are always line anchors, the m flag makes . match newlines (dot-all), \w/\d/\s are ASCII-only while \b and \p{Word} are Unicode-aware, and an unset group never matches a backreference.

    Regex::find

    fn Regex::find(self : Regex, s : String, start? : Int) -> MatchData?

    Finds the first match at or after start (Ruby's String#match(re, start)).

    Regex::find_all

    fn Regex::find_all(self : Regex, s : String) -> Array[MatchData]

    All successive non-overlapping matches (Ruby's scan).

    Regex::group_count

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

    Number of capture groups.

    Regex::gsub

    fn Regex::gsub(self : Regex, s : String, template : String) -> String

    Ruby's gsub(re, template).

    Regex::match_at

    fn Regex::match_at(self : Regex, s : String, pos : Int) -> MatchData?

    Matches only at position pos (like Ruby's \G-anchored match).

    Regex::matches

    fn Regex::matches(self : Regex, s : String) -> Bool

    Whether the pattern matches anywhere in s (Ruby's match?).

    Regex::replace

    fn Regex::replace(self : Regex, s : String, f : (MatchData) -> String) -> String

    Replaces every match with the result of f (Ruby's gsub with a block).

    Regex::replace_first

    fn Regex::replace_first(self : Regex, s : String, f : (MatchData) -> String) -> String

    Replaces the first match with the result of f (Ruby's sub with a block).

    Regex::split

    fn Regex::split(self : Regex, s : String, limit? : Int) -> Array[String]

    Ruby's String#split(re, limit). With limit == 0 (default) trailing empty strings are removed; captured groups are included in the result.

    Regex::sub

    fn Regex::sub(self : Regex, s : String, template : String) -> String

    Ruby's sub(re, template).

    Regex::to_string

    fn Regex::to_string(self : Regex) -> String

    The pattern source in Ruby literal form, e.g. /a+/.

    compile

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

    Compiles pattern. flags may contain m (dot-all, Ruby's meaning).

    test {
    let re = @regex.compile("(\\w+)@(\\w+)")
    guard re.find("mail: joe@example") is Some(m) else { fail("no match") }
    debug_inspect(m.group(2), content="Some(\"example\")")
    }
    fn re(pattern : String, flags? : String) -> Regex

    Like compile but aborts on an invalid pattern. Intended for literal patterns.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io