gossamer/regexp

Types

The result of exec.

  • value is the matched substring (the full match, group 0).
  • captures contains the numbered capture groups, group 1 onwards. None indicates a group that didn’t match.
  • named_captures contains only the named groups that matched.
  • index is the 0-based position of the match in the input.

Match-level indices data from the HasIndices flag is not currently exposed.

pub type Match {
  Match(
    value: String,
    captures: List(option.Option(String)),
    named_captures: dict.Dict(String, String),
    index: Int,
  )
}

Constructors

  • Match(
      value: String,
      captures: List(option.Option(String)),
      named_captures: dict.Dict(String, String),
      index: Int,
    )

A JS RegExp for matching patterns against strings. Mutable for Global and Sticky flags — last_index advances after each match.

See RegExp on MDN.

pub type RegExp

Values

pub fn escape(string: String) -> String

Escapes string so it can be safely embedded in a regex pattern as a literal substring.

pub fn exec(
  regex: RegExp,
  against input: String,
) -> Result(Match, Nil)

Returns the next match of regex in input, or an error if no match. With the Global or Sticky flag, advances last_index.

pub fn flags(of regex: RegExp) -> List(regexp_flag.RegExpFlag)

The flags of regex in canonical order (alphabetical by flag character).

pub fn has_indices(of regex: RegExp) -> Bool
pub fn is_dot_all(of regex: RegExp) -> Bool
pub fn is_global(of regex: RegExp) -> Bool
pub fn is_ignore_case(of regex: RegExp) -> Bool
pub fn is_multiline(of regex: RegExp) -> Bool
pub fn is_sticky(of regex: RegExp) -> Bool
pub fn is_unicode(of regex: RegExp) -> Bool
pub fn is_unicode_sets(of regex: RegExp) -> Bool
pub fn last_index(of regex: RegExp) -> Int

The position at which the next exec will start matching, when the regex has the Global or Sticky flag.

pub fn new(pattern: String) -> Result(RegExp, js_error.JsError)

Creates a new RegExp from pattern. Returns an error if the pattern is not a valid regular expression.

pub fn new_with(
  pattern: String,
  with flags: List(regexp_flag.RegExpFlag),
) -> Result(RegExp, js_error.JsError)

Creates a new RegExp from pattern with the given flags. Returns an error if the pattern is invalid or the flags are incompatible (e.g., both Unicode and UnicodeSets).

pub fn set_last_index(of regex: RegExp, to index: Int) -> RegExp

Sets last_index. Mutates the regex.

pub fn source(of regex: RegExp) -> String
pub fn test_(regex: RegExp, against input: String) -> Bool

Tests whether input contains a match for regex. With the Global or Sticky flag, advances last_index.

Search Document