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) regexp
Compiles 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")
false
match
match(expr, s string) bool
Returns true if the string s contains any match of the regular expression pattern.
>>> regexp.match("ab+a", "abba")
true
>>> regexp.match("[0-9]+", "nope")
false
Types
regexp
Represents a compiled regular expression.
Methods
regexp.match
match(s string) bool
Returns true if the string s contains any match of the regular expression pattern.
>>> r := regexp.compile("a+"); r.match("a")
true
regexp.find
find(s string) string
Returns 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) []string
Returns 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) []string
Returns 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) string
Returns 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) []string
Splits the string s into a slice of substrings separated by the regular expression pattern.
>>> r := regexp.compile("a+"); r.split("baaab")
["b", "b"]