Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"(?i)" does not work with accents

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 ?

like image 368
Brad Avatar asked Oct 02 '12 11:10

Brad


People also ask

How do I type an I with an accent?

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.

How do I type í on my keyboard?

í = Alt + 0237. Í = Alt + 0205.

What is this letter í?

Í, í (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).

How do I enable accents?

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.


1 Answers

Just replace (?i) with (?iu) - it will turn on unicode case-insensitive matching

like image 168
Konstantin V. Salikhov Avatar answered Sep 20 '22 05:09

Konstantin V. Salikhov