string.splitRegex()

Split a String using a provided regular expression.

Signature

splitRegex(regex: String) => Array<String>

Description

Splits the calling String at every occurrence of a provided regular expression, used as a delimiter string.

The calling String isn’t changed. Multiple, adjacent delimiters in the calling String result in an empty element in the resulting Array.

Parameters

Parameter Type Required Description

regex

String

true

Regular expression to split the calling string[] at. Splits at every matching substring. Supports Java regex.

Return value

Type Description

Array<String>

Array of Strings resulting from the split.

Examples

'foo bar baz'.splitRegex('\\W+')
[
  "foo",
  "bar",
  "baz"
]
\