OWASP Validation Regex Repository

What the OWASP Validation Regex Repository is, how it differs from validation libraries and regex testers, and how to vet its patterns before using them.

What the repository is

The OWASP Validation Regex Repository is a collection of regular expressions published under the Open Worldwide Application Security Project (OWASP). It covers common structured input such as email addresses, IP addresses, dates and postal codes. Treat it as a community-contributed reference list, not a tested validation library. No version history, maintenance status or per-pattern test results were available for this review, so nothing here should be read as confirmation that any pattern in it is correct or safe.

To find it, search the OWASP site for the repository name. OWASP has reorganized and archived many older wiki-era pages over the years. Check the page's current location and whether anyone still maintains it before relying on it.

How it differs from related resources

Resource | What it offers | Main limitation
OWASP Validation Regex Repository | Ready-made patterns for common input formats, under a security-focused organization's name | Patterns are contributed rather than guaranteed; correctness, performance and maintenance status must be verified by the user
General regex pattern libraries and snippet sites | Large, searchable collections, often with user ratings or comments | Quality varies widely and security behavior is rarely considered
Regex testers | Interactive matching against sample input, often with flavor selection and match explanations | Show what a pattern does, not whether it is the right rule for your data
Validation libraries and framework validators | Maintained, tested functions for formats like email, URLs and IP addresses | Add a dependency and may not match unusual business rules
OWASP input validation guidance | Principles such as allowlisting, validating on the server and validating type and range, not just syntax | Explains approach rather than supplying finished patterns

Is it suitable for your intended use?

Use the repository as a starting point and a learning aid, not as a drop-in source of production validation. Its main benefit is speed: you get a first draft of a pattern for a common format without writing it from scratch. The decisive tradeoff is that you take on full responsibility for testing that draft. That includes checking it for over-matching, under-matching and catastrophic backtracking. A pattern copied without review can fail silently in either direction.

  • Reasonable uses: studying how a format can be expressed as a regex; drafting a pattern you will then test and adapt; quick client-side hints where the server validates again.
  • Poor fits: security-critical server-side validation with no further testing; formats with complex official grammars, such as full email address syntax or URLs; input from international users when the pattern assumes ASCII.
  • Better alternatives: a maintained validation library or a built-in parser (for example, an IP address or date parser) when your platform provides one; a simple length and character allowlist when the full format does not matter to your application.

Where these patterns can go wrong

Validation regexes fail in two directions. A pattern that is too loose accepts malformed or malicious input. A pattern that is too strict rejects legitimate users: plus signs in email local parts, long top-level domains, hyphenated or apostrophe-containing names. Neither failure is visible from reading the pattern alone. Run each pattern against a set of known-good and known-bad samples drawn from your real data.

Regular expression denial of service

Most mainstream regex engines (in JavaScript, Java, Python, .NET, PHP and Ruby) use backtracking. Certain constructs, especially a quantified group that itself contains a quantifier, can take exponential time on crafted input that almost matches. OWASP's own guidance on regular expression denial of service (ReDoS) explains the problem and has cited a pattern attributed to this repository as an example of a vulnerable expression. Check the current version of that guidance yourself. The example below is illustrative and not taken from the repository.

Vulnerable shape (nested quantifiers):
  ^(a+)+$

Input that triggers heavy backtracking in many engines:
  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!

Equivalent pattern without the nesting:
  ^a+$

Before adopting any pattern, look for nested quantifiers, alternations with overlapping branches inside a repeated group, and patterns that run on untrusted input of unbounded length. Mitigations include rewriting the pattern, enforcing a maximum input length before matching, and using a match timeout where the platform supports one (.NET does, for example). Another option is a linear-time engine such as RE2 or Rust's regex crate, which avoid catastrophic backtracking but do not support backreferences or lookaround.

Copying a pattern into your code

A pattern that works in one place can behave differently after you paste it elsewhere. The most common problem is escaping. A pattern shown in its raw form must be escaped differently depending on how your language represents it.

Raw pattern (US ZIP or ZIP+4):
  ^\d{5}(-\d{4})?$

JavaScript regex literal:
  /^\d{5}(-\d{4})?$/

Python raw string:
  r"^\d{5}(-\d{4})?$"

Java string literal (backslashes doubled):
  "^\\d{5}(-\\d{4})?$"
  • Flavor differences: lookbehind, named groups, possessive quantifiers and Unicode property classes are not supported identically across engines. Confirm that each construct works in your target engine.
  • Anchor behavior: in Python and Java, $ can match before a final newline, and in Ruby ^ and $ always match at line boundaries. Where full-string matching matters, use \A and \z (Python uses \Z), Python's fullmatch, or Java's matches().
  • Case and multiline flags: a pattern written assuming a case-insensitive or multiline flag will behave differently without it.
  • Invisible characters: text copied from web pages can carry non-breaking spaces, zero-width characters or typographic quotes that change what the pattern matches. Retype suspicious characters or inspect the pattern in an editor that shows them.
  • Tester settings: choose the same flavor and flags in a regex tester as in your code, or the tester's result will not carry over.

Readability for the next maintainer

Dense one-line validation patterns are hard to review, which matters because review is what makes a borrowed pattern safe to use. Where your engine supports it, a verbose or extended mode lets you split the pattern across lines and comment each part. Note in a code comment where the pattern came from and what you changed.

import re

ZIP_PATTERN = re.compile(r"""
    \A
    \d{5}          # five-digit ZIP code
    (?:-\d{4})?    # optional ZIP+4 extension
    \Z
""", re.VERBOSE)

International input and inclusivity

Many published validation patterns use ASCII character classes such as [a-zA-Z]. These reject accented letters, non-Latin scripts and internationalized domain names. For fields like personal names, addresses or free text, a strict format regex often does more harm than good. A length limit, rejection of control characters and correct output encoding are usually more appropriate. If you need letter matching beyond ASCII, check whether your engine supports Unicode property classes and how it treats combining marks.

Checklist before adopting a pattern

  • Confirm the pattern expresses the rule you actually need, not a broader or narrower one.
  • Test it against realistic valid and invalid samples, including edge cases from your own data.
  • Inspect it for nested quantifiers and overlapping alternations, and test it with long near-miss input.
  • Cap input length before matching, and validate on the server even if the client also checks.
  • Verify flavor, flags and anchors in your target language.
  • Prefer a maintained library or built-in parser when one exists for the format.
  • Record the pattern's source and your modifications next to the code.

What this review could not confirm

No subject-specific evidence was available for this review. It does not confirm the repository's current location or maintenance status, the number or list of patterns it contains, or whether any individual pattern has been corrected since publication. No patterns were tested for this article. The guidance above rests on general, verifiable behavior of regex engines and input validation practice. Check the repository's current state directly before deciding to use anything from it.