Regular expression - match all words but match unique words only once

后端 未结 3 1299
不知归路
不知归路 2020-12-16 04:23

Is it possible to use a regular expression to match all words but match unique words only once? I am aware there are other ways of doing this however I\'m interested

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-16 05:20

    Pretty close, just readd the \b in the negative lookahead

    /(\w+\b)(?!.*\1\b)/
    

    See it on Rubular

提交回复
热议问题