Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to match ASCII non-alphanumeric characters

Tags:

java

regex

I need a regex to match ASCII non-alphanumeric characters. The regex should not match non-ASCII characters. I am using the following:

   "[\\u0000-\\u002f\\u003a-\\u0040\\u005b-\\u0060\\u007b-\\u007f]"

Can I simplify this regex ?

like image 572
Michael Avatar asked Dec 25 '22 05:12

Michael


1 Answers

Yes you can use a character class intersection. Example:

[\\p{ASCII}&&\\P{Alnum}]

This means: intersection between all ascii characters and all non alphanumeric characters

like image 102
Casimir et Hippolyte Avatar answered Dec 27 '22 19:12

Casimir et Hippolyte