Regex
Learn how to use regex in Vale.
Vale runs its rules on regexp2, in its RE2 compatibility mode: the syntax of Go's standard regexp package, plus the lookahead and lookbehind assertions that package leaves out.
This guide provides an overview of regex syntax supported by Vale, along with tips for writing regular expressions in YAML files.
Syntax
The most commonly used assertion constructs are:
Positive lookahead:
(?=re)Negative lookahead:
(?!re)Positive lookbehind:
(?<=re)Negative lookbehind:
(?<!re)
This extended syntax is supported everywhere in Vale, except for script-based rules (which are limited to the standard Go regex syntax).
YAML
Wrap all regex in single (') or double (") quotes to avoid YAML interpreting special characters:
Single quotes (
'): Prevent YAML from interpreting any characters except single quotes themselves.Double quotes (
"): Allow YAML to interpret escape sequences like\nand\t, so you’ll need to escape backslashes.
In general, this means that you should prefer single quotes for most cases:
If you need to use a single quote in your regex, you can escape it with another single quote:
Vale Studio
Vale Studio provides a rule editor that integrates with regex101 to allow you to inspect the compiled regex pattern and test it against sample text. This can be a helpful way to debug your regex patterns.

Common Issues
Last updated