Go Regex Tester
Test regular expressions written for Go (regexp (RE2)) — with warnings for anything that works differently there, and Go code to copy.
//g
Go regex syntax at a glance
- Literal
- regexp.MustCompile(`pattern`) — a raw string in backticks
- Named group
- (?P<name>…) or (?<name>…) (Go 1.22+)
- Replacement
- ${1}, ${name} (write ${1}x, not $1x)
- Flags
- inline only: (?i), (?m), (?s), (?U)
- Find all
- re.FindAllString(text, -1)
What's different in Go
- →Go uses RE2: matching time grows linearly with the input, so it can't be hit by catastrophic backtracking (ReDoS).
- →That's why there's no lookahead, lookbehind or back-references — rewrite the pattern, or post-filter matches in Go code.
- →\A and \z are supported; \Z isn't. Without (?m), $ matches only at the very end.
- →\d and \w are ASCII; use \p{Nd} and \p{L} for Unicode.
Frequently asked
How do I write a lookahead in Go?
You can't — RE2 doesn't support lookaround. Capture more and check the extra part in code, run a second regexp on the match, or use a backtracking package such as regexp2 if you accept its risks.
Why is my replacement $1suffix empty in Go?
Go reads $1suffix as a group named "1suffix". Write ${1}suffix to end the group reference explicitly.