JavaScript code to filter out common words in a string

后端 未结 6 1479
生来不讨喜
生来不讨喜 2020-12-15 12:20

I\'m trying to build JavaScript code that reads one string (say a sentence of English text), then outputs another string of (comma-separated) words that were \"uncommon\". S

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-15 13:14

    How about this?

    sentence.replace(/\b(?:the|it is|we all|an?|by|to|you|[mh]e|she|they|we...)\b/ig, '');
    

    This should remove all common words from your sentence. Just split the remaining string the way you want.

提交回复
热议问题