← All notes

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

See also

Claims

Sources

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

Permanent ID: iil:note:sgpdvkdh

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.},
}

Markdown

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.

All artifact files (JSON index)

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.