GUIDE深度 · Deep dive
Common Regex: Email, URL, Phone
A perfect email, URL or phone regex barely exists; regex is good for format screening, not proving something exists. Define the rules first (length, allowed characters, country), then write the smallest useful pattern.
Common patterns
Email screen: ^[^\s@]+@[^\s@]+\.[^\s@]+$
URL screen: ^https?://[^\s]+$
China mobile: ^1[3-9]\d{9}$
When not to use regex
Use a parser for HTML/JSON/XML, not regex.
Verify email by sending a message and phone by SMS code.
FAQ
How strict should an email regex be?
Keep it practical; too strict rejects valid addresses, and the real check is a verification email.
Will a URL regex miss cases?
Yes; IDNs, relative paths and brackets can all slip through.