Get the first letter of each word in a string using regex

后端 未结 6 937
天命终不由人
天命终不由人 2021-01-13 04:10

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[]         


        
6条回答
  •  一整个雨季
    2021-01-13 04:25

    Edit Took some suggestions in the comments, but kept the \S because \w is only alpha-numeric and might break unexpectedly on any other symbols.

    Fixing the regex and still using split:

    name.split("(?<=[\\S])[\\S]*\\s*")
    

提交回复
热议问题