Go regexp: RE2 regular expression search in linear time
Answer: Package regexp implements regular expression search. The accepted syntax is the syntax accepted by RE2, except for \C. Matches are guaranteed to run in time linear in the size of the input. MatchString reports whether the string contains any match of the regular expression.
Examples
package main
import "regexp"
func main() {
re := regexp.MustCompile(`foo+[0-9]*`)
_ = re.MatchString("foo123")
}
Notes
A Regexp is safe for concurrent use by multiple goroutines, except for configuration methods. Find, FindAll, and their String and Submatch variants name the common helpers. Empty matches abutting a preceding match are ignored. For an overview of the syntax, see the regexp/syntax package.
Reference list
Thepackage implements regular expression search.Matchesrun in time linear in the size of the input.MatchStringreports whether the string contains any match.
See also
Claims
- id: C1 claim: The package implements regular expression search. source: S1 evidence: "Package regexp implements regular expression search"
- id: C2 claim: Matches run in time linear in the size of the input. source: S2 evidence: "guaranteed to run in time linear in the size of the input"
- id: C3 claim: MatchString reports whether the string contains any match. source: S2 evidence: "MatchString reports whether the string s // contains any match of the regular expression re"
Sources
- [S1] regexp package. Go docs. https://pkg.go.dev/regexp . License: BSD-3-Clause. Accessed 2026-11-18.
- [S2] regexp.go. Go source. https://raw.githubusercontent.com/golang/go/master/src/regexp/regexp.go . License: BSD-3-Clause. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go docs, regexp package; Go source, regexp.go. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Go docs, regexp package; Go source, regexp.go. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "Go regexp: RE2 regular expression search in linear time." iinventedlight Library, iil:note:sgpdvkdh, version of 2026-11-18. https://iinventedlight.com/library/notes/go-regexp/. License: CC-BY-4.0.
@misc{iil_note_sgpdvkdh,
author = {{iinventedlight}},
title = {{Go regexp: RE2 regular expression search in linear time}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/go-regexp/},
note = {Permanent ID iil:note:sgpdvkdh. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- go-regexp.table.json (table; CC-BY-4.0)
- go-regexp.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-regexp.md.