Try Install Learn Blog API Packages GitHub
Pages

Regexp

Functions for working with regular expressions.

Functions

create
(
input
:
String
)
:
Regexp

Creates a new regular expression from a string.

(Regexp.create("test")
|> Regexp.toString()) == "/test/"
createWithOptions
(
input
:
String
options
:
Regexp.Options
)
:
Regexp

Creates a new regular expression using the given options.

(Regexp.createWithOptions(
  "test",
  {
    caseInsensitive = true,
    multiline = true,
    unicode = true,
    global = true,
    sticky = true
  })
|> Regexp.toString()) == "/test/gimuy"
escape
(
input
:
String
)
:
String

Escapes the given input to use in the regular expression.

Regexp.escape("-{") == "\\-\\{"
match
(
input
:
String
regexp
:
Regexp
)
:
Bool

Returns whether or not the given regular expression matches the given string.

(Regexp.create(",")
|> Regexp.match("asd,asd")) == true
matches
(
input
:
String
regexp
:
Regexp
)
:
Array(Regexp.Match)

Returns all of the matches of the given regular expession agains the given string.

(Regexp.createWithOptions(
  "\\w",
  {
    caseInsensitive = true,
    multiline = false,
    unicode = false,
    global = true,
    sticky = false
  })
|> Regexp.matces("a,b,c,d") == [
  {
    submatches = [],
    match = "a",
    index = 0
  }
]
  \match : Regexp.Match => match.match + "1")) == "a1,b1,c1,d1"
replace
(
input
:
String
replacer
:
Function(Regexp.Match, String)
regexp
:
Regexp
)
:
String

Replaces the matches of the given regular expression using the given function to caluclate the replacement string.

(Regexp.createWithOptions(
  "\\w",
  {
    caseInsensitive = true,
    multiline = false,
    unicode = false,
    global = true,
    sticky = false
  })
|> Regexp.replace(
  "a,b,c,d",
  \match : Regexp.Match => match.match + "1")) == "a1,b1,c1,d1"
split
(
input
:
String
regexp
:
Regexp
)
:
Array(String)

Splits the given string by the given regular expression.

(Regexp.create(",")
|> Regexp.split("a,b,c,d")) == ["a", "b", "c", "d"]
toString
(
regexp
:
Regexp
)
:
String

Returns the string representation of the given regular expression.

(Regexp.create("test")
|> Regexp.toString()) == "/test/"