I'm using WordsUtils
to capitalize
words.
Since I can't define which words should be capitalized, I have to make another implementation after capitalize function to put some words lowercase.
The words that should be lowercase are: ["da, de, di, do, du, das, des, dis, dos, dus"]
.
So, my code
at the moment is:
public static String capitalize(String word) {
String newWord = WordUtils.capitalizeFully(word);
newWord = newWord.replaceAll("\\b([d|D][a-zA-Z]{1,2})\\b", "$1").toLowerCase();
return newWord;
}
Example of inputs:
- josé dAs sIlVa
- Jorge De PAuLa
- MaRiA DAS PauLas
The problem is that the replaceAll is puttng every word lowercase , not only the prepositions that matches the Pattern
.