regexp
Module regexp provides regular expression matching.
The supported regular expression syntax is exactly as described in the Go regexp (opens in a new tab) documentation.
Functions
compile
compile(expr string) regexpCompiles a regular expression string into a regexp object.
>>> regexp.compile("a+")
regexp("a+")
>>> r := regexp.compile("a+"); r.match("a")
true
>>> r := regexp.compile("[0-9]+"); r.match("nope")
falsematch
match(expr, s string) boolReturns true if the string s contains any match of the regular expression pattern.
>>> regexp.match("ab+a", "abba")
true
>>> regexp.match("[0-9]+", "nope")
falseTypes
regexp
Represents a compiled regular expression.
Methods
regexp.match
match(s string) boolReturns true if the string s contains any match of the regular expression pattern.
>>> r := regexp.compile("a+"); r.match("a")
trueregexp.find
find(s string) stringReturns the leftmost match of the regular expression pattern in the string s.
>>> r := regexp.compile("a+"); r.find("baaab")
"aaa"regexp.find_all
find_all(s string) []stringReturns a slice of all matches of the regular expression pattern in the string s.
>>> r := regexp.compile("(du)+"); r.find_all("dunk dug in the deep end")
["du", "du"]regexp.find_submatch
find_submatch(s string) []stringReturns a slice of all matches of the regular expression pattern in the string s, and the matches, if any, of its subexpressions.
>>> r := regexp.compile("a(b+)a"); r.find_submatch("abba")
["abba", "bb"]regexp.replace_all
replace_all(s, repl string) stringReturns a copy of the string s with all matches of the regular expression pattern replaced by repl.
>>> r := regexp.compile("a+"); r.replace_all("baaab", "x")
"bxb"regexp.split
split(s string) []stringSplits the string s into a slice of substrings separated by the regular expression pattern.
>>> r := regexp.compile("a+"); r.split("baaab")
["b", "b"]