HomeGeneratorsDeveloper ToolsRegex Generator

Regex Generator

Developer Tools

Generate ready-to-use regex patterns for email, phone, URL, dates, Indian IDs, and more. Paste a test string to check for a match — free, browser-based.

What is a Regex?

A Regex Generator provides ready-to-use regular expression patterns for the most common validation and parsing tasks in web development — covering international formats like email addresses and URLs alongside India-specific identifiers like PAN numbers, GST numbers, Aadhaar, and Indian mobile numbers.

Regular expressions are one of the most powerful tools in a developer's toolkit, but writing them correctly from scratch is time-consuming and error-prone. A single misplaced bracket or a forgotten escape character can produce a pattern that silently passes invalid input or rejects valid input. The generator provides verified patterns for 20 common use cases, formatted as JavaScript-compatible regex literals with the surrounding / delimiters and any chosen flags already applied.

The tool also serves as a quick reference: select a pattern type to see a valid example string alongside the regex, which is useful both for understanding what the pattern matches and for generating test data that will pass the validation.

For Indian developers, the collection covers the five IDs most commonly validated in web applications: PAN (for income tax and financial KYC flows), GST number (for B2B invoicing), Aadhaar (basic 12-digit format check), Indian mobile number (10 digits starting with 6–9), and Indian pincode (6-digit format). The PAN Validator and GST Validator apply these same patterns with detailed segment-by-segment explanations of what each part means.

Use the UUID Generator to generate IDs for test records you create while verifying these patterns in your application. For building test data tables using regex-validated values, the Markdown Table Generator lets you document your validation rules in a readable format.

How to use this Regex calculator

  1. Select a pattern type from the dropdown — 20 common patterns from email and URL to Indian IDs and colour codes.
  2. Choose flags if needed — leave as None for single-value validation; select Global for extracting multiple matches from a longer string; select Case-insensitive for patterns where capitalisation should not matter.
  3. Click Generate — the pattern and a valid example appear immediately.
  4. Optionally enter a test string in the Test String field to verify the pattern against a specific value. The test result updates automatically.
  5. Copy the pattern from the Regex Pattern output field and paste it into your code.
  6. Adapt for your language if needed — strip the / delimiters for Python (re.compile(r'pattern')), Java (Pattern.compile("pattern")), or SQL (REGEXP 'pattern').

Formula & Methodology

All 20 patterns are anchored with ^ (start of string) and $ (end of string), making them suitable for full-string validation rather than substring matching. The anchors can be removed if you need to find the pattern within a longer text.

Selected pattern details:

| Pattern Type | Key rules |
|---|---|
| Email | [^\s@]+@[^\s@]+\.[^\s@]+ — no spaces or @ before the @, a dot and non-empty TLD after |
| Indian Mobile | [6-9]\d{9} — first digit 6–9, exactly 9 more digits |
| URL | https?:// prefix, no whitespace in the rest |
| IPv4 | Each octet 0–255 using 25[0-5]\|2[0-4]\d\|[01]?\d\d? |
| PAN | [A-Z]{5}[0-9]{4}[A-Z] — 5 uppercase letters, 4 digits, 1 uppercase letter |
| GST | [0-9]{2}[A-Z]{5}[0-9]{4}[A-Z][1-9A-Z]Z[0-9A-Z] — 2-digit state, embedded PAN, entity code |
| Aadhaar | [1-9][0-9]{11} — 12 digits, first digit non-zero |
| Hex colour | #([A-Fa-f0-9]{6}\|[A-Fa-f0-9]{3}) — 3 or 6 hex digits after # |
| Slug | [a-z0-9]+(-[a-z0-9]+)* — lowercase alphanumeric segments joined by hyphens |

The test uses JavaScript's RegExp constructor with the raw pattern string and the selected flags, run synchronously in the browser.
Frequently Asked Questions
What is a regular expression (regex)?
A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. It is used to check whether a string matches a particular format (validation), to extract portions of a string (parsing), or to replace matching text (substitution). Regular expressions are supported in virtually every programming language — JavaScript, Python, Java, Go, PHP, Ruby — and in many command-line tools like `grep`, `sed`, and `awk`.
What patterns does the Regex Generator cover?
The generator includes 20 patterns covering the most common use cases in web development and Indian-specific contexts: email address, Indian mobile number (10-digit, starting with 6–9), Indian phone with +91 country code, URL (http/https), IPv4 address, IPv6 address, ISO date (YYYY-MM-DD), Indian date format (DD/MM/YYYY), time (HH:MM and HH:MM:SS), Indian PAN number, GST number, Aadhaar number (basic format), Indian pincode, hex colour code, positive integer, decimal number, credit card number, username, and URL slug.
How do I use the generated pattern in JavaScript?
Copy the pattern and use it directly as a JavaScript regex literal or pass the pattern string to the RegExp constructor. For example, for an email pattern: `const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;` and then `emailRegex.test('user@example.com')` returns `true`. If you copy the pattern with flags (e.g. `/pattern/gi`), split the string at the last `/` to separate the pattern from the flags when using `new RegExp(pattern, flags)`.
What are regex flags and when should I use them?
Flags modify how the regex engine applies the pattern. The `g` (global) flag finds all matches in a string rather than stopping after the first. The `i` (case-insensitive) flag makes the pattern match regardless of letter case — useful for email validation where `User@Example.COM` should match the same pattern as `user@example.com`. For most single-value validation (checking if one field matches a format), no flags are needed. Use `g` when extracting multiple matches from a longer text.
Why does the Indian mobile number pattern start with [6-9]?
In India, active mobile numbers are allocated in the 6xxx, 7xxx, 8xxx, and 9xxx ranges. Numbers starting with 0–5 are either landline prefixes, unused blocks, or reserved numbers. The pattern `^[6-9]\d{9}$` enforces the 10-digit length and the 6–9 starting digit, which together cover all TRAI-allocated mobile numbers. Numbers starting with lower digits are not valid mobile numbers in India and will correctly fail this pattern.
Does this tool validate that an email address actually exists?
No. Regex validation checks format only — it confirms the string has characters before an `@`, a domain part, and a top-level domain extension. It does not verify that the domain exists, that the mailbox is active, or that the address can receive email. To verify a real email address, you need to either send a confirmation email or use an email verification API. Regex catches obvious typos and format errors; it is not a substitute for delivery verification.
What is the difference between anchored and unanchored patterns?
An anchored pattern uses `^` at the start and `$` at the end to require the pattern to match the entire string. An unanchored pattern can match anywhere within a longer string. All patterns in this generator are anchored — `^...$` — which is the correct behaviour for input validation (you want the entire field value to match the format, not just a substring within it). When extracting matches from a longer document, you would remove the anchors and use the `g` flag instead.
Can I use these patterns for form validation in HTML?
Yes. HTML5 `<input pattern='...'>` accepts a regex pattern (without the surrounding slashes and without anchors — the browser implicitly anchors the pattern). For example: `<input type='text' pattern='[6-9]\d{9}' title='Enter a valid 10-digit Indian mobile number'>`. Note that HTML pattern matching is case-sensitive by default and does not support flags directly. For full regex flexibility, use JavaScript validation alongside or instead of the HTML `pattern` attribute.
What does the test string field do?
The Test String field lets you verify the pattern against a specific value before using it in your code. Enter any string in the field and the generator runs the regex against it, reporting whether it matches and — for global-flag patterns — listing the individual matches found. This saves switching to a browser console or a separate regex testing tool. The test runs entirely in your browser; the string is not transmitted anywhere.
Why does the IPv6 pattern only match the full 8-group form?
The generator uses a simplified IPv6 pattern that matches the full expanded form (`2001:0db8:85a3:0000:0000:8a2e:0370:7334`) but not the compressed form that omits leading zeros or uses `::` to abbreviate consecutive zero groups. A fully RFC-4291-compliant IPv6 regex that handles all abbreviation forms is extremely long and difficult to maintain. For production validation of IPv6 addresses, use a dedicated library function rather than a regex — most languages provide one.
Are these patterns suitable for production code?
The patterns in this generator are industry-standard, production-grade patterns for the common use cases they cover. The email pattern is intentionally pragmatic (matches the vast majority of real-world email formats) rather than fully RFC 5322-compliant (the spec-compliant regex is thousands of characters long and impractical). For Indian ID validators (PAN, GST, Aadhaar), the patterns match the official format specifications. Always test any regex against a representative sample of your actual data before deploying, particularly for edge cases in your specific user base.