I have to test whether a string is included in another one but without considering case or accents (French accents in this case).
For example the function must return true
if I search for "rhone"
in the string "Vallée du Rhône"
.
The Collator is useful for string comparison with accents but does not provide a contains
function.
Is there an easy way to do the job ? A regex maybe ?
Additional information :
I just need a true
/ false
return value, I don't care about number of matches or position of the test string in the reference string.
You can use Normalizer to reduce strings to stripped-down versions that you can compare directly.
Edit: to be clear
String normalized = Normalizer.normalize(text, Normalizer.Form.NFD);
String ascii = normalized.replaceAll("[^\\p{ASCII}]", "");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With