Get first letter of each word in a string, in JavaScript

后端 未结 17 1682
后悔当初
后悔当初 2020-12-05 04:00

How would you go around to collect the first letter of each word in a string, as in to receive an abbreviation?

Input: "Java Script Object

17条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 04:30

    @BotNet flaw: i think i solved it after excruciating 3 days of regular expressions tutorials:

    ==> I'm a an animal

    (used to catch m of I'm) because of the word boundary, it seems to work for me that way.

    /(\s|^)([a-z])/gi
    

提交回复
热议问题