---
source: https://iinventedlight.com/library/notes/go-regexp.md
title: "Go regexp: RE2 regular expression search in linear time"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Go docs); BSD-3-Clause (Go source); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go regexp"
tags: [go, regexp, re2, match, compile]
client: Librarian
sources:
  - id: S1
    title: "regexp package"
    publisher: Go docs
    url: https://pkg.go.dev/regexp
    accessed: 2026-11-18
    license: "BSD-3-Clause"
  - id: S2
    title: "regexp.go"
    publisher: Go source
    url: https://raw.githubusercontent.com/golang/go/master/src/regexp/regexp.go
    accessed: 2026-11-18
    license: "BSD-3-Clause"
---
# 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

```go
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

- `The` package implements regular expression search.
- `Matches` run in time linear in the size of the input.
- `MatchString` reports whether the string contains any match.

## See also

- [go-slices](https://iinventedlight.com/library/notes/go-slices/)
- [go-error-handling](https://iinventedlight.com/library/notes/go-error-handling/)
- [go-modules-basics](https://iinventedlight.com/library/notes/go-modules-basics/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
