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
- Extract values from log linesBuild a pattern with capture groups that pulls request IDs, status codes or durations out of raw logs.
- Learn the core syntax quicklyCharacter classes, quantifiers, anchors, groups and lookarounds explained with examples you can reuse.
- Preview a search-and-replaceTest a replacement with $1 or named group references before running it across files.
- Compare text before and after a replaceDiff the original and transformed text to confirm only the intended lines changed.
- Pick apart a URL instead of regexing itFor URLs, a real parser is safer than a pattern; break one into protocol, host, path and parameters.
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
- Anchor validation patterns with ^ and $ so the whole input must match, not just part of it.
- Prefer specific character classes such as [^"]* over .* to keep matches tight and fast.
- Use named groups and the x-style comments your language supports to keep long patterns readable.
- Test against both matching and non-matching samples, including empty strings and unicode text.
- Do not use regex to parse HTML, JSON or URLs; use a real parser and apply regex only to the extracted values.