I have a Java method that looks for a word inside a phrase ignoring the case sensitivity of the word, and if it finds the word then it removes it from the phrase. The word and the phrase can be anything. They're variant. Here is my code :
private String removeWord( String phrase, String word ) {
phrase = phrase.replaceAll( "(?i)" + word , "" );
return phrase;
}
Things work perfect, unless the word has an accent. For example if the word is "álvarez" and the phrase is "Álvarez phrase", then it won't work as "(?i)" fails to work in that case.
Is there a way to make "(?i)" work with accented characters ?
Most new mobile phones, across both Apple and Android operating systems, will allow you to type an accented letter simply by long-pressing on the letter on the keypad. The various options for that letter will appear in a small box, and you can make a selection.
í = Alt + 0237. Í = Alt + 0205.
Í, í (i-acute) is a letter in the Faroese, Hungarian, Icelandic, Czech, Slovak, and Tatar languages, where it often indicates a long /i/ vowel (ee in English word feel).
Press Shift + Control + ~, then the letter to add a tilde accent. You will find the tilde is the same key used to make the grave accent. Be sure to hold down the Shift key or you will end up with a grave accent instead. Release the keys, then select the desired letter.
Just replace (?i) with (?iu) - it will turn on unicode case-insensitive matching
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