Skip to content

Category · 1 tool · 1 guide

Regex tools

Regular expressions are a compact language for finding patterns in text. Developers use them to validate input, extract fields from logs, rename symbols across a codebase, route URLs, and clean up data before importing it. A single line of regex can replace dozens of lines of string handling code.

That compactness is also the problem. A pattern that looks right often matches too much, too little, or nothing at all, and the reason is buried in a greedy quantifier, a missing anchor or an unescaped dot. Writing regex blind and running the whole program to test it is slow. Seeing matches highlighted as you type is the fastest way to get a pattern right.

The tools here use the JavaScript regex engine built into your browser, so results match what your Node.js or front-end code will do. Your sample text stays on your machine.

Tools in this category

Common tasks

Key concepts

Quantifiers
*, + and ? repeat the previous item zero-or-more, one-or-more or zero-or-one times, and {2,5} sets an exact range. By default they are greedy and match as much as possible; add ? to make them lazy.
Anchors
^ and $ match the start and end of the input, or of each line with the m flag. \b matches a word boundary. Without anchors, a validation pattern can match a substring of invalid input.
Capture groups
Parentheses capture the text they match so you can reuse it as $1 in replacements or read it in code. Named groups like (?<year>\d{4}) make patterns self-documenting.
Lookahead and lookbehind
(?=...) and (?<=...) check what comes after or before a position without consuming it. They are useful for rules like "a number followed by px" without including px in the match.
Catastrophic backtracking
Nested quantifiers such as (a+)+ can make the engine try exponentially many paths on certain input, freezing a process. This is the basis of ReDoS attacks.

Best practices

  1. Anchor validation patterns with ^ and $ so the whole input must match, not just part of it.
  2. Prefer specific character classes such as [^"]* over .* to keep matches tight and fast.
  3. Use named groups and the x-style comments your language supports to keep long patterns readable.
  4. Test against both matching and non-matching samples, including empty strings and unicode text.
  5. Do not use regex to parse HTML, JSON or URLs; use a real parser and apply regex only to the extracted values.

Guides