Try Install Learn Blog API Packages GitHub
Pages
core

Search
Entities

Regexp

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
(
regexp
:
Regexp
input
:
String
)
:
Bool

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

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

Returns all of the matches of the given regular expression against 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
(
regexp
:
Regexp
input
:
String
replacer
:
Function(Regexp.Match, String)
)
:
String

Replaces the matches of the given regular expression using the given function to calculate 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
(
regexp
:
Regexp
input
:
String
)
:
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/"