Regex Library - Battle-Tested Patterns for CN Mobile, ID, Plates & More
Free curated regex library: 14 battle-tested patterns for CN mobile/ID/plates (incl. new-energy)/credit codes, email, URL, IPv4/IPv6, dates, and postcodes — each with notes and samples, copy or jump to the online tester.
This tool runs in your browser: what you enter is processed on your device and normally never appears in a request to any server.
Usage Guide
Emails, phones, URLs, IPs, dates — the classic failure in form validation isn’t regex syntax but copying a “community-famous” pattern that is either too loose (lets junk through) or too strict (blocks real users). This library curates 14 validation regexes, each with its use case, dialect notes, and a set of positive/negative samples — all runnable in place, so what you see is the regex’s actual behavior. Copy-and-use is fully local; suited for keeping front-end and back-end validation aligned.
1. How to use
All patterns and verification logic ship inside the page; no network calls.
- Browse or search for the target format; open an entry to see the pattern, notes, and sample sets.
- Try it live: type any string and see the match verdict immediately — every entry has an in-page runner.
- Copy the pattern or the JavaScript literal form into your form code.
2. Why positive and negative samples matter
A regex is only as trustworthy as what it correctly rejects and accepts. Phone patterns circulating online often block the 166/198/199 ranges added after 2017; copy-pasted IPv4 checks happily accept 999.999.999.999. Every entry here ships with curated should-pass and should-fail samples that actually execute on the page — the behavior you observe is the behavior you get, not the behavior a blog post claims.
3. Dialect warnings
- JavaScript and Python are close but not identical: lookarounds work in both, named groups differ.
- Java string literals double the escaping (\\d) — wrap accordingly after copying.
- Go’s RE2 has no backtracking: entries using (?!…) lookaheads won’t port directly.
- Database regex functions (MySQL 8 / PostgreSQL) differ in semantics — run the samples in the target dialect before trusting a migration.
4. Regex or parser?
Regex fits shape validation (the form of an email or URL), not semantics: whether a mailbox domain exists, whether a URL resolves, whether a date is a business day — those need lookups or parsing. A practical split: loose regex on the front end for instant feedback, strict validation (regex plus business rules) on the back end, with both sides aligned on one sample set. Export these positive/negative samples as your project’s test cases.
5. Maintenance
- Formats drift with policy: phone ranges expand, postal codes are reshuffled. Take the sample snapshot along with the pattern so future updates have a baseline.
- Keep one canonical regex source per team to prevent behavioral drift between copies.
- Pair with the China Test Data Generator for round-trip checks against your validators.
FAQ
Fourteen validation regexes — email, phone numbers, URLs, IPv4/IPv6, dates, postal codes and more — each annotated with use-case notes and dialect warnings, plus a set of positive and negative samples that run live.
They execute right on the page, so what you see is the regex's real behavior. That exposes circulated-version pitfalls early — community phone patterns that reject the 166/198/199 ranges added after 2017, or IPv4 copies that wave 999.999.999.999 through.
JavaScript literals work as-is. Python spells named groups (?P<name>…) rather than (?<name>…); Java string literals need an extra escaping layer, so regex \d becomes \\d in source; Go's RE2 has no backtracking, so entries containing (?!…) lookaheads will not run there; and database regex functions (MySQL 8, PostgreSQL) differ enough that you should test the samples in the target dialect before trusting them.
No — regex validates shape. Whether a domain exists, a URL is reachable, or a date is a real business day is semantics that calls for lookups or parsing. A practical split: a loose regex up front for instant feedback, strict validation (regex plus business rules) in the backend, both sides aligned on the same samples — and this library's samples export straight into your test cases.
They do — new number ranges and administrative re-zoning gradually make old regexes too strict. Take the sample snapshot along with the regex so future updates have a baseline, and standardize on one source within the team to prevent per-person drift. When you need test data to exercise the validation, round-trip it with the China test data generator.
No — every regex and the verification engine are baked into the page and run in place, without passing through any server.
Related Tools
Related Articles
Regex Not Matching? 6 Causes and Fixes (With Examples)
Regex not matching when it looks correct? Fix the 6 most common causes — greedy quantifiers, missing /g /i /m flags, unescaped special characters, lookaround direction, newline handling, and Unicode /u — with wrong-vs-right examples and a free online tester.
Regex Matches Nothing / Greedy .* Swallows Results — How to Fix
Online regex test matches nothing, or greedy .* eats too much, or groups capture nothing? Explains greedy vs lazy, escaping special chars, and anchors — with a step-by-step debug using our regex tester.
Online Regex Explainer: Visualize and Understand Regular Expressions
Learn how to parse and understand regular expressions — lazy quantifiers, lookarounds, named groups, Unicode properties, and how to pair an explainer with a tester.