You want to check whether an email is valid, pull every phone number out of a block of text, or find all the <img> tags in some HTML. Doing that by hand is miserable. Regular expressions (regex) are the tool for "find text that matches a pattern." This post explains, in plain English, what regex is, the few symbols that do most of the work, copy-paste patterns for common jobs, the greedy-vs-lazy trap, and how to test regex free.
1. What a regular expression is
A regex is a tiny search language: a string of characters that describes a pattern instead of literal text. The pattern cat matches the word "cat". The pattern c.t matches "cat", "cot", "cut" — the dot means "any single character." Instead of searching for one fixed word, you search for a shape of text.
2. The building blocks you actually need
.— any single character*— the previous item, zero or more times+— the previous item, one or more times?— the previous item, optional (zero or one)[abc]— any one of a, b, or c[0-9]or\d— any digit\w— a word character (letter, digit, underscore)^and$— start and end of the string/line( )— group, so you can repeat or capture part of the match|— OR, e.g.cat|dog
3. Copy-paste patterns for real jobs
- Email:
[^\s@]+@[^\s@]+\.[^\s@]+ - US phone:
\d{3}-\d{3}-\d{4} - URL:
https?://[^\s]+ - 3-digit number:
\b\d{3}\b
These are starting points, not perfect validators — real email/URL specs are far stricter. Use them to find candidates, then sanity-check.
4. The greedy-vs-lazy trap
By default, * and + are greedy: they grab as much as possible. The pattern <.*> on <a> x <b> matches the whole thing, not just <a>. Add ? to make it lazy: <.*?> stops at the first >. This single character fixes most "my regex ate too much" bugs.
5. Test your regex free with Jisubao
Never guess whether a pattern works — run it:
- Open the Jisubao Regex Tester;
- Paste your text sample;
- Type the pattern and watch matches highlight live;
- Toggle flags like global (match all) and case-insensitive;
- Everything runs locally — your text stays in the browser.
Free, no signup.
6. Quick FAQ
Q: Is regex the same in every language? — Mostly, with small differences (Python, JavaScript, and PCRE vary in advanced features). The basics are portable.
Q: Should I validate emails with regex? — For UX, a loose check is fine; for real validation, send a confirmation link. Regex alone misses many valid addresses.
Q: Why is my pattern matching too much? — Almost always the greedy trap in step 4. Add ?.
Regex looks like line noise until you learn a dozen symbols — then it becomes the fastest text-search tool you own. Test every pattern live, watch for greedy matches, and let the tool show you what actually matches.
👉 Try it now: Jisubao online Regex Tester →