Validators

Validate JSON, YAML, XML and more — 1 free tool in our Developer Tools category.

The tool

Validation tools let you confirm that a pattern or a document behaves the way you expect before it reaches production code, where a mistake is expensive to diagnose.

Testing regular expressions

The Regex Tester evaluates a pattern against sample text and highlights every match, along with the contents of any capture groups. Building a regex incrementally against real examples is far more reliable than writing one from memory and hoping: start with the simplest pattern that matches one case, then widen it, checking after each change that you have not started matching something unintended.

Habits that prevent regex bugs

Be deliberate about greediness. .* matches as much as it can, so a pattern intended to capture one HTML attribute will happily swallow the rest of the line. The non-greedy .*? matches the shortest possible span, which is usually what you meant.

Anchors change meaning with flags. ^ matches the start of the string normally, but the start of each line when the multiline flag is set. A pattern that works on a single line and fails on a document is often just this.

Prefer named capture groups — (?<year>\d{4}) — over counting numbered ones. They survive someone inserting another group ahead of them, and they document what the pattern is extracting.

Finally, know when not to use a regex. Nested structures like HTML and JSON are not regular languages, and a regex that appears to parse them will fail on valid input. Use a real parser for those, and keep regular expressions for genuinely pattern-shaped problems.

Frequently Asked Questions

Why does my pattern match more than I expected?▼

Usually greedy quantifiers. `.*` extends as far as it can while still allowing a match, so it runs past the first candidate ending. Switch to the non-greedy `.*?`, or replace `.` with a character class that excludes the delimiter you want to stop at.

Are regex flavours the same across languages?▼

The core syntax is broadly shared, but details differ. Lookbehind support, named group syntax, Unicode property escapes and the behaviour of `$` around trailing newlines all vary between JavaScript, PCRE, Python and Go's RE2. Test against the engine you will actually run on.

Can I use a regex to validate email addresses?▼

Only approximately. The full grammar for a valid address is far more permissive than people expect, and patterns that try to be exhaustive become unmaintainable. A pragmatic pattern that checks for a single `@` with something plausible either side, followed by sending a confirmation email, is the standard approach.