Regular expressions using Go's regexp package.
use "re"All functions take the pattern as the first argument. Invalid patterns panic (use try/or to handle).
Returns true if the pattern matches anywhere in the string.
re.test("^\\d+$", "42") # true
re.test("^\\d+$", "abc") # falseReturns the first match, or nil if no match.
re.find("\\d+", "abc123def") # "123"
re.find("\\d+", "no numbers") # nilReturns all matches as an array.
re.find_all("\\d+", "a1b2c3") # ["1", "2", "3"]Replaces the first match.
re.replace("\\d+", "a1b2c3", "X") # "aXb2c3"Replaces all matches. Supports backreferences ($1, $2).
re.replace_all("\\d+", "a1b2c3", "X") # "aXbXcX"
re.replace_all("(\\w+)@(\\w+)", "foo@bar", "$1 at $2") # "foo at bar"Splits the string by the pattern. Returns an array.
re.split("\\s+", "hello world") # ["hello", "world"]
re.split(",\\s*", "a, b, c") # ["a", "b", "c"]Returns a hash with "match" (full match string) and "groups" (array of capture groups), or nil if no match.
m = re.match("(\\w+)@(\\w+)", "foo@bar.com")
m["match"] # "foo@bar"
m["groups"][0] # "foo"
m["groups"][1] # "bar"Invalid patterns panic with a descriptive message. Use try/or to handle:
result = try re.test("[invalid", "test") or "bad pattern"