Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In java how I can delete Vowels are 'a', 'e', 'i', 'o' and 'u

Tags:

java

string

regex

How can I delete vowels from a String except the vowel at the end of word?

For example "Please come to my party"

To return "Plse cme to my prty"

like image 696
Joo Avatar asked May 19 '11 09:05

Joo


2 Answers

string.replaceAll("[aeiou]\\B", "")

Reads: Match all vowels ([aeiou]) that are not followed by an "end of word" (\\B). For more information read the Javadoc on java.util.regex.Pattern

like image 108
Lukas Eder Avatar answered Sep 21 '22 00:09

Lukas Eder


Turn the String into a char array.

Iterate through it.

Append each character to a StringBuilder, unless the next character is an alphabetic character.

like image 44
Kilian Foth Avatar answered Sep 23 '22 00:09

Kilian Foth