Regex to Match Alphanumeric Strings

Validate alphanumeric strings with this regex. Matches strings containing only letters and digits, no special characters. Free tool.

Regular Expression

/^[a-zA-Z0-9]+$/

Token Breakdown

TokenDescription
^Anchors at the start of the string (or line in multiline mode)
[a-zA-Z0-9]Character class — matches any one of: a-zA-Z0-9
+Matches the preceding element one or more times (greedy)
$Anchors at the end of the string (or line in multiline mode)

Detailed Explanation

This regex validates that a string contains only alphanumeric characters (letters and digits). Here is the token-by-token breakdown:

^ — Anchors the match at the start of the string. This ensures no non-alphanumeric characters precede the matched content.

[a-zA-Z0-9]+ — A character class matching one or more alphanumeric characters. It includes three ranges: a-z for lowercase letters, A-Z for uppercase letters, and 0-9 for digits. The + quantifier requires at least one character, so empty strings will not match.

$ — Anchors the match at the end of the string, ensuring no non-alphanumeric characters follow.

Together, the anchors and character class ensure the entire string consists exclusively of letters and digits. No spaces, underscores, hyphens, or other special characters are allowed.

This pattern is commonly used for validating usernames, product codes, reference numbers, and other identifiers that should contain only basic alphanumeric characters. It is one of the most fundamental regex patterns and appears frequently in form validation.

Note that this pattern is ASCII-only and does not match accented characters (like e with accent or u with umlaut) or characters from non-Latin scripts. If you need to support international characters, use Unicode-aware patterns or the \w shorthand (which includes underscores). For strict alphanumeric validation of ASCII characters only, this pattern is the standard choice.

Example Test Strings

InputExpected
Hello123Match
ABCMatch
hello worldNo Match
test_nameNo Match
abc123defMatch

Try It — Interactive Tester

//
gimsuy
No matches found.
Pattern: 14 charsFlags: noneMatches: 0

Ctrl+Shift+C to copy regex

Customize this pattern →