Java regular expression to remove all non alphanumeric characters EXCEPT spaces

You need to double-escape the \ character: "[^a-zA-Z0-9\\s]"

Java will interpret \s as a Java String escape character, which is indeed an invalid Java escape. By writing \\, you escape the \ character, essentially sending a single \ character to the regex. This \ then becomes part of the regex escape character \s.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)