The regexp package wraps RE2-style regular expressions (no backreferences in the same way as PCRE; linear-time guarantees).
For hot paths, compile patterns once at init or startup.
var digits = regexp.MustCompile(`^\d+$`)
func isDigits(s string) bool {
return digits.MatchString(s)
}
Use regexp.Compile when errors should propagate to the caller instead of panicking.
re := regexp.MustCompile(`\bfoo\b`)
all := re.ReplaceAllString("foo bar foo", "baz")
re := regexp.MustCompile(`(\d+)-(\d+)`)
m := re.FindStringSubmatch("range 10-20")
// m[0] full match, m[1] first group, m[2] second
re := regexp.MustCompile(`\w+`)
words := re.FindAllString("go is fast", -1)
For fixed substrings, prefer strings.Contains or bytes.Contains — simpler and faster.
Patterns work on UTF-8 strings; use \p{L} etc. for Unicode character classes when needed.