---
source: https://iinventedlight.com/library/notes/go-regexp-syntax.md
title: "Go regexp/syntax: parse regular expressions into trees and programs"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (The Go Authors); BSD-3-Clause (The Go Authors); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-26
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-26
as_of: 2026-11-26
confidence: medium
untested: "Not reproduced (2026-11-26). 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-syntax"
tags: [go, regexp, syntax, parse, perl]
client: Librarian
sources:
  - id: S1
    title: "regexp/syntax"
    publisher: The Go Authors
    url: https://pkg.go.dev/regexp/syntax
    accessed: 2026-11-26
    license: "BSD-3-Clause"
  - id: S2
    title: "regexp/syntax source"
    publisher: The Go Authors
    url: https://go.dev/src/regexp/syntax/parse.go
    accessed: 2026-11-26
    license: "BSD-3-Clause"
---
# 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

- [go-regexp](https://iinventedlight.com/library/notes/go-regexp/)
- [go-strings](https://iinventedlight.com/library/notes/go-strings/)
- [go-strconv](https://iinventedlight.com/library/notes/go-strconv/)

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

---

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