Regex to Match Special Characters
Copy the pattern, paste your text, and watch every symbol light up. Below: how to require at least one special character.
/
/
What this pattern matches
It matches any single character that is not a letter, digit, or whitespace — in other words, punctuation and symbols.
Part by part
[^A-Za-z0-9\s] — a negated class: anything except letters, digits, and whitespace.
Requiring a special character
To check a password contains at least one symbol, use a lookahead on the whole string: ^(?=.*[^A-Za-z0-9\s]).+$.
Use it in your code
Python
import re
text = "Password123! and user@example.com \u2014 50% off #deal"
pattern = r'''[^A-Za-z0-9\s]'''
for m in re.finditer(pattern, text):
print(m.group())
JavaScript
const text = "Password123! and user@example.com \u2014 50% off #deal";
const re = new RegExp(String.raw`[^A-Za-z0-9\s]`, "g");
console.log(text.match(re));
FAQ
How do I define which symbols count?
List them explicitly, e.g. [!@#$%^&*()] , instead of a negated class, when only specific symbols are allowed.
Why is whitespace excluded here?
Spaces are usually not treated as special characters. Drop \s from the class if you want them matched too.
Does it match emoji?
Yes — emoji are non-alphanumeric, so a negated ASCII class matches them as special characters.