Quick regex reference
| Pattern | Matches |
|---|---|
\d \w \s | digit, word character (letter, digit, _), whitespace |
. | any character except a new line (tick “s” to include new lines) |
[abc] [^abc] [a-z] | one of, none of, range |
* + ? {3} {2,5} | 0 or more, 1 or more, optional, exactly 3, 2 to 5 |
^ $ \b | start, end (of each line with “m”), word boundary |
(…) (?:…) (?<name>…) | capture group, non-capturing group, named group |
a|b | a or b |
(?=…) (?!…) | followed by, not followed by |
Flags: g find all matches, i ignore case, m make ^ and $ work on each line, s let . match new lines, u Unicode mode (needed for \p{L} letter classes).
Frequently asked questions
What is the regex for an Indian mobile number?
^[6-9]\d{9}$: ten digits starting with 6, 7, 8 or 9. Add (?:\+91[\s-]?|0)? at the start to allow a +91 or 0 prefix.
What is the PAN card regex?
^[A-Z]{5}[0-9]{4}[A-Z]$: five letters, four digits and one letter, for example ABCDE1234F.