I am relatively new to java and I have to create a pig latin translator for a phrase. Here's the code I have right now so that I can split the phrase that the user would enter. Sorry for the improper formatting.
String english = "Queen of all reptiles";
String[] words = english.split ("\\s+");
for (int i = 0 ; i < words.length ; i++) {
System.out.println (words [i]);
}
The output for this code is:
Queen
of
all
reptiles
However, I would like to split the String english by spaces and special characters so that if
String english = "Queen. of reptiles."
it would output:
Queen
.
of
reptiles
.
I attempted to do this: String[] words = english.split ("[^a-zA-Z0-9]", "");
but it does not work.