Regular Expressions 101

Community Library

3

Email validation for modern applications

  • JavaScript
  • Unit Tests
  • Recommended
Practical email validation for modern applications. Balances common address formats with strict length, dot and domain rules. Supports plus addressing, long TLDs and ASCII internationalized domains that simpler patterns may reject. Includes named captures and extensive tests. A practical fit for most SaaS signups, contact forms and contact management. Rules neither too loose nor too strict. Supported cases Ordinary syntax at Gmail, Outlook/Hotmail, Yahoo, iCloud and work domains. Uppercase and lowercase ASCII letters, numbers, dots, underscores, hyphens and apostrophes in usernames. Plus addressing supports empty tags and additional + signs. Trailing dots and consecutive dots are rejected. Usernames may start or end with _, - or ', but must contain a letter or digit. Subdomains, numeric domain labels and internal hyphens. Alphabetic TLDs of 2–63 characters and ASCII xn-- domain forms for internationalized names. Checks character lengths: Total: 6–254. Local part: 1–64 (including plus addressing). Domain labels: 1–63. Named captures: local_part, username, plus_alias, domain. The regex checks for the xn-- structure, not full IDNA validity. Valid examples Narrower patterns may reject some of these valid email address formats. Accepted example What it demonstrates user.name@example.com Common dotted username User.Name@Example.Com Mixed case o'connor@example.com Apostrophe in the username _support-@example.com Permitted username edges user+news@example.com Plus addressing user+@example.com Empty plus tag user+news+work@example.com Additional plus signs user@example.technology Longer TLD user@xn--bcher-kva.de Internationalized domain in ASCII Invalid examples Loose patterns may accept some of these malformed email addresses or input formats. Rejected example Reason .user@example.com Leading local-part dot user.@example.com Trailing local-part dot user..name@example.com Consecutive local-part dots user@example..com Empty domain label user@_example.com Underscore in the domain user@-example.com Leading domain-label hyphen user@name@example.com Multiple @ signs aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@example.com Local part exceeds 64 characters user name@example.com Space in local part User Name <user@example.com> Display-name wrapper, not a bare address user@example.com,other@example.com Address list, not one address Tabs, CR/LF, control characters and surrounding text are also rejected. Intentional limits These policy exclusions include standards-valid forms; they are not inherently unsafe. See RFC 5321 and SMTPUTF8. Excluded case Example IP-literal domain user@[127.0.0.1] Single-label domain user@localhost Quoted local part "user"@example.com Raw Unicode address 名前@example.com Extra local-part symbols: !, %, /, = user%name@example.com Punctuation-only username ___@example.com Apostrophe inside a plus tag user+new's@example.com Username dot immediately before + user.+news@example.com Tests and security Verified against 560 test cases, covering valid and invalid forms, length boundaries, aliases, domains, case and control characters. Length guards and dot-separated segments limit ambiguity associated with catastrophic backtracking. Adversarial tests found no catastrophic slowdown in the tested engines. Rejecting control characters reduces log-injection risks. Still use server-side validation, safe mail APIs, parameterized queries, output encoding and email verification. Regex cannot prove domain existence, mailbox ownership or deliverability, or prevent injection alone. See OWASP guidance. Speed Measured across all the test suite: median of seven batch averages, precompiled regex. Speed depends on hardware, engine and input. Engine Duration per validation Node.js 24.19 ~0.13 µs Ruby 3.2.2 ~0.92 µs About regex101.com performance: Change the Unit Tests tab to "Show only failed tests" to improve the tests speed. Usage Use the JavaScript flavor without flags. To enforce whole-string matching for Ruby/PCRE2, replace the opening ^ with \A and both $ anchors with \z (one inside the length lookahead and one at the end). Other flavors may need syntax changes.
Submitted by Tiago Cussiol
1

ตรวจสอบพยัญชนะต้นตัวสะกดสระและวรรณยุกต์ไทย

  • JavaScript
  • Match
ตรวจสอบพยัญชนะต้น (ต้องมี) ตรวจตัวสะกดสำหรับสระที่ต้องมี ตรวจสอบการวางสระและวรรณยุกต์ไทย หมายเหตุ การตรวจสอบตัวสะกดในภาษาไทยตรวจสอบได้ยากเพราะภาษาไทยเป็นภาษาที่เขียนติด ๆ กันไม่มีการแบ่งคำอย่างชัดเจนทำให้การอ่านภาษาไทยผู้อ่านต้องใช้ความหมายของคำในการตัดสินการอ่านแบ่งคำตามความเหมาะสมเช่นคำว่า "ตากลม" อาจอ่านเป็น "ตาก-ลม" ก็ได้ หรืออ่านเป็น "ตา-กลม"ก็ได้ ดังนั้นการเขียน Regex เพื่อทำการตรวจสอบอาจช่วยได้ระดับหนึ่ง อ่าจมีผิดบ้างถูกบ้าง แต่ก็ถือว่าเป็นเครื่องมือที่ใช้ช่วยเหลือในการตรวจสอบเพิ่มเติมได้ 80% ของความเป็นไปใด้ก็แล้วกันนะครับ หวังว่าการเขียนเพิ่มเติมส่วนนี้ จะมีประโยชน์บ้างไม่มากก็น้อย
Submitted by อธิปัตย์ ล้อวงศ์งาม
1

Regex for Matching Documentation Websites

  • JavaScript
  • Unit Tests
Regex for Matching Documentation Websites This repository contains a powerful regular expression designed to match URLs that commonly point to documentation-related websites. The regex is optimized for flexibility, covering various terms and URL patterns. Regex Pattern ^.*(?:\.|\/)(docs|documentation|help|guide|manual|reference|api|kb|support|resources|wiki|developer|how-to|tutorials|examples|learn|instructions)(?:\.|\/)?.*$ Purpose This regex is intended to identify URLs that contain keywords associated with documentation or support websites. It handles common patterns in subdomains, directories, and file paths. Explanation ^.*: Matches any characters at the beginning of the URL (any prefix). (?:\.|\/): Matches either a period (.) or a forward slash (/) preceding the keyword. (docs|documentation|help|guide|manual|...): Matches any of the keywords listed in the group. (?:\.|\/)?: Allows an optional period (.) or forward slash (/) following the keyword. .*$: Matches any characters following the keyword (any suffix). Examples Positive Examples The following URLs should match the regex: https://example.com/docs http://docs.example.com https://example.com/documentation https://sub.domain.com/docs/index.html https://example.com/help https://api.example.com/docs http://example.com/manual/index.html https://wiki.example.com http://developer.example.com/guide https://example.com/tutorials/docs/page https://kb.example.com/docs/tutorial.html https://example.com/resources/documentation/tutorial.html http://example.com/reference/help/documentation.html https://developer.example.com/docs/tutorials/index.html http://support.example.com/documentation/overview https://resources.example.com/docs/v1/tutorial https://example.com/how-to/documentation http://example.com/api/reference/docs https://example.com/reference/v2/index.html http://example.com/docs/resources/api.html Negative Examples The following URLs should not match the regex: https://example.com/documentary http://helpful.example.com https://manuals.example.com http://example.com/references https://example.com/resourceful http://example.com/wiki-books https://apiary.example.com http://example.com/documents http://example.com/documentable https://help-center.example.com http://manual.example.com/docsystem https://example.com/resourcesful http://api.example.comary https://example.net/instructions-v1 http://example.org/learned-tutorial http://example.com/support-center Author Jeremy Georges-Filteau Website Github
Submitted by jgeofil