RegexBuilder · regex answers
Regex for alphanumeric characters
/^[A-Za-z0-9]+$/
ASCII letters and digits, one or more, nothing else. \w is not a substitute: it also allows the underscore, which is how underscores end up in fields that were supposed to reject them.
What each part does
| [A-Za-z0-9] | one ASCII letter or digit |
| + | one or more of them |
| ^ … $ | and the whole string is nothing but those |
Tested against real input
Every row below was run through the engine when this page was built. The third column is the substring the pattern actually matched.
| Input | Result | Matched |
|---|---|---|
| abc123 | matches | abc123 |
| ABC | matches | ABC |
| 999 | matches | 999 |
| abc_123 | no match | — |
| abc-123 | no match | — |
| abc 123 | no match | — |
| café | no match | — |
The mistake to avoid
Reaching for ^\w+$. It permits _, and under Unicode rules it permits accented letters too, so it is a different check than the one you asked for.
Try it on your own text
Paste this pattern and your input, see each match highlighted with its capture groups, step through what the engine did, and get the equivalent syntax for JavaScript, Python, Java, Go and PCRE.
Open RegexBuilderOther regex answers
- Regex for an email address
- Regex for a US phone number
- Regex for an IPv4 address
- Regex for a URL
- Regex for a date in YYYY-MM-DD format
- Regex to match digits only
- Regex to find special characters
- Regex for a strong password
- Regex to match whitespace
- Regex to trim leading and trailing whitespace
- Regex for a UUID
- Regex for a hex colour code