Alphanumeric

2 snippets in Regular Expressions

RXRegular Expressions

Ranges [a-z] [A-Z] [0-9]

RX · Character Classes
Syntax
[a-z]  [A-Z]  [0-9]  [a-zA-Z0-9]
Example
JS:  'Room 4B'.match(/[A-Z][0-9]/)
Py:  re.search(r'[0-9][A-Z]', 'Room 4B')
Output
JS: null (no uppercase letter followed by digit)
Py: "4B" (digit followed by uppercase letter)

Note Order matters. [a-z] covers lowercase Latin letters. Combine ranges for broader matches. Ranges use Unicode/ASCII code points, so [A-z] accidentally includes [, \, ], ^, _, ` -- always use [A-Za-z] instead.

\w Word Character and \W

RX · Character Classes
Syntax
\w  =>  [a-zA-Z0-9_]    \W  =>  [^a-zA-Z0-9_]
Example
JS:  'user_name@host'.match(/\w+/g)
Py:  re.findall(r'\W+', 'hello, world! 42')
Output
JS: ["user_name", "host"]
Py: [", ", "! "]

Note \w includes the underscore. Like \d, Python's \w matches Unicode letters by default (accented chars, CJK, etc.) while JS \w sticks to ASCII unless the u flag is combined with Unicode property escapes.

Frequently asked questions

How does Regular Expressions handle alphanumeric?
Regular Expressions covers this with 2 copy-ready snippets on this page. The "Ranges [a-z] [A-Z] [0-9]" snippet in Regular Expressions uses `[a-z] [A-Z] [0-9] [a-zA-Z0-9]`.
Which pattern does the Regular Expressions example use?
The "Ranges [a-z] [A-Z] [0-9]" snippet uses `[a-z] [A-Z] [0-9] [a-zA-Z0-9]`, from the Character Classes section of the Regular Expressions cheat sheet.
What other Regular Expressions snippets are shown for "alphanumeric"?
Besides "Ranges [a-z] [A-Z] [0-9]", this page also shows "\w Word Character and \W".
Is there anything to watch out for?
Yes. For "Ranges [a-z] [A-Z] [0-9]": Order matters. [a-z] covers lowercase Latin letters. Combine ranges for broader matches. Ranges use Unicode/ASCII code points, so [A-z] accidentally includes [, \, ], ^, _, ` -- always use [A-Za-z] instead.