Java remove non Latin-basic characters from string

Viewed 4752

Let's say I have the following code:

String description = "★★★★★  ♫ ♬ This description ✔✔  ▬ █ ✖  is a mess. ♫ ♬ ★★★★★";

I'd like to remove the non-Latin characters: ✔, ▬, █, ✖, ♫, ♬ and ★.

And have it become this: This description is a mess.

I know there's probably tons of these wingdings-like characters, so instead of specifying what I'd like to remove, I think it's better to list what I want to keep: Basic Latin and Latin-1 supplements characters.

I found that I can use the following code to remove everything but the basic latin characters

String clean_description = description.replaceAll("[^\\x00-\\x7F]", "").trim();

But is there a way to also preserve the Latin-1 supplement characters?

2 Answers
Related