How to use the Regex Generator
- 1. Choose a patternPick from 15 ready patterns, build password rules, or test your own regex.
- 2. Add test stringsType strings one per line, or leave it blank to see the built-in examples.
- 3. Copy the codeGet the regex and ready snippets for JavaScript, Python and Java.
Worked example: Indian mobile numbers
The mobile pattern is ^(?:\+91[\-\s]?|0)?[6-9]\d{9}$. It accepts 9876543210, +91 9876543210 and 09876543210, and rejects 5876543210 (Indian mobile numbers start with 6–9), 98765 4321 (a space in the middle) and +91987654321 (only 9 digits after +91). With no test strings entered, the result table shows each built-in example with its expected result, so you can see the pattern really behaves as described.
Password rules
The builder turns your choices into lookaheads. Requiring 8 or more characters with an uppercase letter, a lowercase letter, a digit, a special character and no spaces gives ^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[^A-Za-z0-9])(?!.*\s).{8,}$. Each (?=…) checks one rule anywhere in the string without consuming characters, and the final part checks the length.
Tested in two languages
Every ready pattern's examples were checked to match or not match as labelled, both in JavaScript and with Python's re.fullmatch, so the snippets behave the same in both. Remember that format checks aren't validation: a PAN, GSTIN or Aadhaar number can have the right shape and still not exist, and Aadhaar numbers are sensitive data that shouldn't be stored casually.
Other ready patterns cover IPv4 addresses, 24-hour times, hex colours, usernames, URL slugs and Indian vehicle registration numbers, each with notes on what they deliberately don't check. You can also paste any regex of your own to test it.
Frequently asked questions
Why are ^ and $ removed in the Python snippet?
re.fullmatch already requires the whole string to match, so they aren't needed.
Can I test my own regex?
Yes. Choose 'Test my own pattern' and type it without slashes; invalid patterns get a clear error.
Is the email pattern complete?
No regex fully covers the email standard. This one accepts normal addresses; confirm addresses by sending an email.
Is the regex generator free?
Yes. You can use the regex generator without signing up. The first time you run it, we ask once for your name and WhatsApp number; after that the regex generator and every other Uncodemy tool open straight away.