RRegexBuilder
Get RegexBuilder

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.

InputResultMatched
abc123matchesabc123
ABCmatchesABC
999matches999
abc_123no match
abc-123no match
abc 123no 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 RegexBuilder

Other regex answers