String processing

Module regex

Regular expressions.

re(s)
Obtain a regular expression from a string representation s.
Type Regex, r: Regex
r.match(s)
Return true if r matches s, else false.
r.list(s)
Return the list of non-overlapping matches.
r.split(s)
Split the string s into parts, using pattern r as a separator.
r.groups(s)
Return the list of groups if r matches s, else null.
r.replace(s,f)
Replace every non-overlapping match x with f(x).

Module string.split

Split strings into parts.

Extension of String, s: String

s.words(), s.words(regex)
Filter words out of a string.
s.split(), s.split(sep)
Split a string into parts separated by characters in the string sep.

Examples:

uniq = |a| set(a).sort()
text = read("input.txt")

a = uniq(text.words().map(|s| s.lower()))

lines = text.split("\n")

a = "1, 12, 3, 04".words("[0-9]+").map(int)

a = "1, 12, 3, 04".split(",\s").map(int)