Regular Expression To Match Non-Alphanumeric Characters

A Regular Expression to match non-alphanumeric characters. This can be useful to match any character that is not a number of letter.

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

Explain:

  • [] Character set. Match any character in the set.
    • a-z Range. Matches a character in the range “a” to “z”. Case sensitive.
    • A-Z Range. Matches a character in the range “A” to “Z”. Case sensitive.
    • 0-9 Range. Matches a character in the range “0” to “9”. Case sensitive.

Matches:

  • @
  • #
  • Space

Non-matches:

  • 12345
  • abcde

See Also:

Regex Is Copied!