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 (or a flag string) cannot be compiled.

    RegexTimeout

    pub suberror RegexTimeout {
    RegexTimeout(pattern~ : String, limit~ : Int)
    } derive(
    Debug
    )

    Raised when a search exceeds its backtracking step budget (the analogue of Ruby's Regexp::TimeoutError). limit is the budget that was exhausted.

    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. Matching works on code points: a match never starts or ends inside a surrogate pair, even though offsets are reported in UTF-16 code units.

    Each search operation runs under a step budget (see compile); the try_* methods raise RegexTimeout when it is exhausted, the other methods abort.

    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)). A start inside a surrogate pair is rounded up to the next code point.

    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). There is no match at an offset inside a surrogate pair.

    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+/.

    Regex::try_find

    fn Regex::try_find(self : Regex, s : String, start? : Int) -> MatchData? raise RegexTimeout

    Like find, but raises RegexTimeout when the step budget runs out.

    Regex::try_find_all

    fn Regex::try_find_all(self : Regex, s : String) -> Array[MatchData] raise RegexTimeout

    Like find_all, but raises RegexTimeout when the step budget (shared by the whole scan) runs out.

    Regex::try_match_at

    fn Regex::try_match_at(self : Regex, s : String, pos : Int) -> MatchData? raise RegexTimeout

    Like match_at, but raises RegexTimeout when the step budget runs out.

    Regex::try_replace

    fn Regex::try_replace(self : Regex, s : String, f : (MatchData) -> String, once? : Bool) -> String raise RegexTimeout

    Like replace (or replace_first when once is true), but raises RegexTimeout when the step budget (shared by the whole operation) runs out.

    Regex::try_split

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

    Like split, but raises RegexTimeout when the step budget (shared by the whole operation) runs out.

    compile

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

    Compiles pattern. flags may contain Ruby's options: m (dot-all), i (ignore case, using Unicode simple case folding; multi-character folds such as ß = ss are not supported) and x (extended: whitespace and # comments outside classes are ignored). Any other flag is an error. The inline forms (?imx-imx) and (?imx-imx:...) are supported too.

    step_limit bounds the backtracking work of each search operation (a step is one branch or one sub-match); 0 selects the default, which is generous (10M steps plus roughly the square of the input length, see step_limit_for) so that it only trips on catastrophic backtracking.

    Patterns that Onigmo rejects, or that would exceed internal limits (group nesting beyond 256, programs beyond 1M instructions), raise RegexError.

    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\")")
    inspect(@regex.compile("HELLO", flags="i").matches("hello"), content="true")
    }
    fn re(pattern : String, flags? : String, step_limit? : Int) -> Regex

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