Go regexp/syntax: parse regular expressions into trees and programs
Answer: The regexp/syntax package parses regular expressions into trees and compiles those trees into programs, while most callers should stay with package regexp.
Who should use it
This package turns a regular expression into a parse tree and then compiles that tree into a program.
Most clients of regular expressions will use the facilities of package regexp instead of this package.
When parsing with the Perl flag, the understood syntax is the Perl-like form described in the docs.
Parts of that syntax can be turned off by passing alternate flags to Parse.
Word characters and limits
IsWordChar reports whether a rune is a word character while evaluating the zero-width assertions \b and \B.
These assertions are ASCII only.
Flags also record parser behavior, such as whether character classes may match a newline.
A maximum parse-tree height exists so recursion on the tree will not hit the Go stack limit.
See also
Claims
- id: C1 claim: The package parses regular expressions into parse trees and compiles them into programs. source: S1 evidence: "parses regular expressions into parse trees and compiles parse trees into programs"
- id: C2 claim: Most clients should use package regexp instead of this package. source: S1 evidence: "Most clients of regular expressions will use the facilities of package regexp"
- id: C3 claim: Flags control the behavior of the parser. source: S2 evidence: "Flags control the behavior of the parser"
Sources
- [S1] regexp/syntax. The Go Authors. https://pkg.go.dev/regexp/syntax . License: BSD-3-Clause. Accessed 2026-11-26.
- [S2] regexp/syntax source. The Go Authors. https://go.dev/src/regexp/syntax/parse.go . License: BSD-3-Clause. Accessed 2026-11-26.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Go Authors, regexp/syntax; The Go Authors, regexp/syntax source. 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: The Go Authors, regexp/syntax; The Go Authors, regexp/syntax source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "Go regexp/syntax: parse regular expressions into trees and programs." iinventedlight Library, iil:note:atnrc3fc, version of 2026-11-26. https://iinventedlight.com/library/notes/go-regexp-syntax/. License: CC-BY-4.0.
@misc{iil_note_atnrc3fc,
author = {{iinventedlight}},
title = {{Go regexp/syntax: parse regular expressions into trees and programs}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-26},
url = {https://iinventedlight.com/library/notes/go-regexp-syntax/},
note = {Permanent ID iil:note:atnrc3fc. 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-syntax.schema.json (schema; CC-BY-4.0)
- go-regexp-syntax.table.json (table; 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-syntax.md.