I'm trying to strip all characters from a string except:
- Alphanumeric characters
- Dollar sign (
$
) - Underscore (
_
) - Unicode characters between code points
U+0080
andU+FFFF
I've got the first three conditions by doing this:
preg_replace('/[^a-zA-Zd$_]+/', '', $foo);
How do I go about matching the fourth condition? I looked at using X
but there has to be a better way than listing out 65000+ characters.
You can use:
w
- is equivalent of[a-zA-Z0-9_]
x{0080}-x{FFFF}
to match characters between code pointsU
+0080and
U+FFFF`/u
for unicode support in regex