I'm trying to get the first letter of each word in a string using regex, here is what I have tried:
public class Test
{
public static void main(String[] args)
{
String name = "First Middle Last";
for(String s : name.split("(?<=[\S])[\S]+")) System.out.println(s);
}
}
The output is as follows:
F
M
L
How can I fix the regex to get the correct output?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…