Regular expressions — regex for short — are a compact language for describing text patterns. They power search-and-replace, form validation and data extraction across almost every programming language and editor. They look cryptic at first, but the core ideas are simpler than they appear.
What a regex actually is
A regex is a pattern that either matches a piece of text or does not. The simplest pattern is just literal characters: the regex cat matches the word "cat" anywhere it appears. The power comes from special characters that describe categories and repetition rather than exact letters. The best way to learn is to watch matches highlight live, which our regex tester does as you type.
The essential building blocks
A handful of symbols cover most everyday needs: . matches any character; \d matches a digit and \w a word character; * means "zero or more", + means "one or more", and ? means "optional". Brackets define a set — [aeiou] matches any vowel — and ^ and $ anchor to the start and end of a line. Combine them and you can describe surprisingly specific patterns.
A worked example: matching an email
A simple email pattern is \w+@\w+\.\w+ — one or more word characters, an @, more word characters, a dot, then the domain suffix. It is not bulletproof (real email validation is famously tricky), but it shows how the pieces fit together. Paste some sample text into the regex tester and watch every email light up.
Flags change the behaviour
Flags tweak how a pattern runs. The global flag (g) finds every match rather than just the first; case-insensitive (i) ignores capitalisation; and multiline (m) makes ^ and $ match at every line break. Toggling these is often the difference between one match and all of them.
Test before you ship
Regex is powerful but easy to get subtly wrong, so always test against real sample data before using it in code. Our regex tester shows matches and capture groups instantly and privately. To analyse the text itself, the character-frequency counter and word counter are handy companions, and the text diff tool helps you compare results before and after a replacement.