← All notes

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

Sources

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

Permanent ID: iil:note:atnrc3fc

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

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-syntax.md.