#mizchi/js/builtins/regexp

    Regular expressions with JavaScript's RegExp API.

    #Installation

    Add to your moon.pkg.json:

    { "import": [ "mizchi/js", "mizchi/js/builtins/regexp" ] }

    #Overview

    Provides bindings for JavaScript's RegExp object for pattern matching and text manipulation.

    #Usage Example

    fn main {
    // Create a RegExp
    let pattern = @regexp.RegExp::new("\\d+", "g")

    // Test a string
    let matches = pattern.test("abc123") // true

    // Execute pattern
    let result = pattern.exec("test123")

    // String methods with RegExp
    let text = "hello world"
    let replaced = text.replace(pattern, "***")
    }

    #Available Methods

    • test(string) - Test if pattern matches
    • exec(string) - Execute pattern and return match details
    • Pattern properties: source, flags, global, ignoreCase, multiline

    #Reference

    RegExp

    #external
    pub type RegExp

    JavaScript RegExp object wrapper.

    Corresponds to JavaScript's RegExp constructor and object. See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp

    RegExp::dotAll

    fn RegExp::dotAll(self : RegExp) -> Bool

    Check if the dotAll flag is set.

    JavaScript API: RegExp.prototype.dotAll See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/dotAll

    RegExp::exec

    fn RegExp::exec(self : RegExp, s : String) -> RegExpResult?

    Execute the regular expression and return detailed match information.

    JavaScript API: RegExp.prototype.exec() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec

    RegExp::flags

    fn RegExp::flags(self : RegExp) -> String

    Get the flags string of the regular expression.

    JavaScript API: RegExp.prototype.flags See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags

    RegExp::global

    fn RegExp::global(self : RegExp) -> Bool

    Check if the global flag is set.

    JavaScript API: RegExp.prototype.global See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global

    RegExp::hasIndices

    fn RegExp::hasIndices(self : RegExp) -> Bool

    Check if the hasIndices flag is set.

    JavaScript API: RegExp.prototype.hasIndices See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices

    RegExp::ignore_case

    fn RegExp::ignore_case(self : RegExp) -> Bool

    Check if the ignoreCase flag is set.

    JavaScript API: RegExp.prototype.ignoreCase See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase

    RegExp::lastIndex

    fn RegExp::lastIndex(self : RegExp) -> Int

    Get the index at which to start the next match.

    JavaScript API: RegExp.prototype.lastIndex (getter) See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex

    RegExp::matchAll

    fn RegExp::matchAll(self : RegExp, string : String) -> Array[RegExpMatchArray]

    Return all matches of a regular expression against a string.

    JavaScript API: String.prototype.matchAll() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll

    RegExp::match_

    fn RegExp::match_(self : RegExp, string : String) -> RegExpMatchArray?

    Match a regular expression against a string.

    JavaScript API: String.prototype.match() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match

    RegExp::multiline

    fn RegExp::multiline(self : RegExp) -> Bool

    Check if the multiline flag is set.

    JavaScript API: RegExp.prototype.multiline See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline

    RegExp::new

    fn RegExp::new(pattern : String, flags? : String) -> RegExp

    Create a new RegExp instance.

    JavaScript API: new RegExp(pattern, flags) See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp

    RegExp::replace

    fn RegExp::replace(self : RegExp, string : String, replacement : String) -> String

    Replace matches of the regular expression with a string.

    JavaScript API: String.prototype.replace() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace

    RegExp::replace_all

    fn RegExp::replace_all(self : RegExp, string : String, replacement : String) -> String

    Replace all matches of the regular expression with a string.

    JavaScript API: String.prototype.replaceAll() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll

    RegExp::replace_all_fn

    fn RegExp::replace_all_fn(self : RegExp, string : String, replacer : (String, Array[String], Int, String) -> String) -> String

    Replace all matches of the regular expression using a replacer function.

    JavaScript API: String.prototype.replaceAll() with replacer function See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll

    RegExp::replace_fn

    fn RegExp::replace_fn(self : RegExp, string : String, replacer : (String, Array[String], Int, String) -> String) -> String

    Replace matches of the regular expression using a replacer function.

    JavaScript API: String.prototype.replace() with replacer function See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace

    RegExp::search

    fn RegExp::search(self : RegExp, string : String) -> Int

    Search for a match and return the index of the first occurrence.

    JavaScript API: String.prototype.search() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search

    RegExp::set_last_index

    fn RegExp::set_last_index(self : RegExp, index : Int) -> Unit

    Set the index at which to start the next match.

    JavaScript API: RegExp.prototype.lastIndex (setter) See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex

    RegExp::source

    fn RegExp::source(self : RegExp) -> String

    Get the source pattern of the regular expression.

    JavaScript API: RegExp.prototype.source See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source

    RegExp::split

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

    Split a string using the regular expression as the separator.

    JavaScript API: String.prototype.split() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split

    RegExp::sticky

    fn RegExp::sticky(self : RegExp) -> Bool

    Check if the sticky flag is set.

    JavaScript API: RegExp.prototype.sticky See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky

    RegExp::test_

    fn RegExp::test_(self : RegExp, string : String) -> Bool

    Test if the pattern matches the given string.

    JavaScript API: RegExp.prototype.test() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test

    RegExp::to_any

    fn RegExp::to_any(self : RegExp) ->
    Any

    RegExp::to_string

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

    Convert the regular expression to a string.

    JavaScript API: RegExp.prototype.toString() See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString

    RegExp::unicode

    fn RegExp::unicode(self : RegExp) -> Bool

    Check if the unicode flag is set.

    JavaScript API: RegExp.prototype.unicode See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode

    RegExpMatchArray

    pub struct RegExpMatchArray {
    matches : Array[String]
    index : Int?
    input : String?
    groups : Map[String, String]?
    }

    Result of String.match() or String.matchAll() methods.

    Corresponds to the return value of JavaScript's String.prototype.match() and String.prototype.matchAll(). See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll

    RegExpMatchArray::to_any

    RegExpResult

    pub struct RegExpResult {
    full : String
    input : String
    index : Int
    lastIndex : Int
    groups : Map[String, String]?
    }

    Result of RegExp.exec() method.

    Corresponds to the return value of JavaScript's RegExp.prototype.exec(). See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec

    RegExpResult::to_any

    Source Files