How to replace all non-letters in a given string s with the character '*'

For example, Enter

Hi 1 / (¤

The exit should be

Hello ****
+3
source share
2 answers

To your regular expression will work with international characters (for example, for processing of letters with diacritics as letters, for example ä, àand so on), you should use the expression that supports the unicode for the character other than letters

"Héllö 1/(¤".replaceAll("[^\\p{L}\\s]", "*");
+7
source
"Hello 1/(¤".replaceAll("[^A-Za-z\\s]", "*")
+2
source

Source: https://habr.com/ru/post/1728835/


All Articles