Regexp Funcers

reFindAll

Finds all non-overlapping matches in a string.

TypeValue
InputStra string
regexp (param #1)for Str <A Null|Obj<0: Str, start: Num, Any>>a regexp
OutputArr<<A Any>...>array of matches

Matches appear in the output from leftmost to rightmost. Matches that overlap an earlier match (i.e., a match that starts at a lower offset or one that starts at the same offset but is found earlier by the regexp) are not included.

Examples

ProgramTypeValueError
"a" reFindAll~a+~Arr<Null|Obj<0: Str, start: Num, Void>...>[{start: 0, 0: "a"}]
"aa" reFindAll~a+~Arr<Null|Obj<0: Str, start: Num, Void>...>[{start: 0, 0: "aa"}]
"aba" reFindAll~a+~Arr<Null|Obj<0: Str, start: Num, Void>...>[{start: 0, 0: "a"}, {start: 2, 0: "a"}]

reReplaceFirst

Replaces the first match of a regexp in a string with something else.

TypeValue
InputStra string
regexp (param #1)for Str Null|Obj<0: Str, start: Num, Any>a regexp
replacement (param #2)for Obj<0: Str, start: Num, Any> Strtakes a match and returns a string
OutputStrthe input with the first match of the regexp replaced with the corresponding replacement, or unchanged if there is no match

Examples

ProgramTypeValueError
"aba" reReplaceFirst(a+, "c")Str"cba"
"abc" reReplaceFirst(d, "e")Str"abc"
"b0b" reReplaceFirst(\d+, @0 parseInt =n "a" repeat(n))Str"bb"
"b3b" reReplaceFirst(\d+, @0 parseInt =n "a" repeat(n))Str"baaab"
" a b c " reReplaceFirst([abc], "({@0})")Str" (a) b c "

reReplaceAll

Replaces all non-overlapping matches of a regexp in a string with something else.

TypeValue
InputStra string
regexp (param #1)for Str <A Null|Obj<0: Str, start: Num, Any>>a regexp
replacement (param #2)for Obj<0: Str, start: Num, Any> Strtakes a match and returns a string
OutputStrthe input with all matches of the regexp replaced with the corresponding replacement, or unchanged if there is no match

Matches are replaced from leftmost to rightmost. Matches that overlap an earlier match (i.e., a match that starts at a lower offset or one that starts at the same offset but is found earlier by the regexp) are not replaced.

Examples

ProgramTypeValueError
"aba" reReplaceAll(a+, "c")Str"cbc"
"abc" reReplaceAll(d, "e")Str"abc"
" a b c " reReplaceAll([abc], "({@0})")Str" (a) (b) (c) "

reSplit

Splits a string around a regexp.

TypeValue
InputStra string
separator (param #1)for Str Null|Obj<0: Str, start: Num, Any>a regexp
OutputArr<Str...>the parts of the input found in between occurrences of the separator

If the separator regexp matches the empty string, the input is split into its individual code points. Separators are found from leftmost to rightmost. Separators that overlap an earlier separator (i.e., a separator that starts at a lower offset or one that starts at the same offset but is found earlier by the regexp) do not lead to splits.

Examples

ProgramTypeValueError
"zabacad" reSplit~a~Arr<Str...>["z", "b", "c", "d"]
"zabaca" reSplit~a~Arr<Str...>["z", "b", "c", ""]
"abacad" reSplit~a~Arr<Str...>["", "b", "c", "d"]
"abaca" reSplit~a~Arr<Str...>["", "b", "c", ""]
"abaca" reSplit~~Arr<Str...>["a", "b", "a", "c", "a"]
"你好" reSplit~~Arr<Str...>["你", "好"]
"" reSplit~a~Arr<Str...>[""]
"" reSplit~~Arr<Str...>[]

reSplit

Splits a string around a regexp, up to a certain number of times.

TypeValue
InputStra string
separator (param #1)for Str Null|Obj<0: Str, start: Num, Any>a regexp
n (param #2)Nummaximum number of splits to make
OutputArr<Str...>the parts of the input found in between occurrences of the separator

If the separator regexp matches the empty string, the input is split into its individual code points. Separators are found from leftmost to rightmost. Separators that overlap an earlier separator (i.e., a separator that starts at a lower offset or one that starts at the same offset but is found earlier by the regexp) do not lead to splits. At most n splits are made so that the output contains at most n + 1 elements; later separator occurrences are ignored.

Examples

ProgramTypeValueError
"zabacad" reSplit(a, 1)Arr<Str...>["z", "bacad"]
"zabaca" reSplit(a, 1)Arr<Str...>["z", "baca"]
"zabaca" reSplit(a, 3)Arr<Str...>["z", "b", "c", ""]
"zabaca" reSplit(a, 4)Arr<Str...>["z", "b", "c", ""]
"abacad" reSplit(a, 1)Arr<Str...>["", "bacad"]
"abacad" reSplit(a, 2)Arr<Str...>["", "b", "cad"]
"abaca" reSplit(a, 1)Arr<Str...>["", "baca"]
"abaca" reSplit(a, 2)Arr<Str...>["", "b", "ca"]
"abaca" reSplit(a, 3)Arr<Str...>["", "b", "c", ""]
"abaca" reSplit(~~, 2)Arr<Str...>["a", "b", "aca"]
"abaca" reSplit(~~, 1000)Arr<Str...>["a", "b", "a", "c", "a"]
"你好" reSplit(~~, 0)Arr<Str...>["你好"]
"" reSplit(a, 0)Arr<Str...>[""]
"" reSplit(a, 1)Arr<Str...>[""]
"" reSplit(~~, 0)Arr<Str...>[]
"" reSplit(~~, 1)Arr<Str...>[]