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.