Regular expression to find and remove duplicate words

前端 未结 9 940
孤城傲影
孤城傲影 2020-11-30 09:46

Using regular expressions in C#, is there any way to find and remove duplicate words or symbols in a string containing a variety of words and symbols?

Ex.

9条回答
  •  感动是毒
    2020-11-30 10:15

    This seems to work for me

    (\b\S+\b)(?=.*\1)
    

    Matches like so

    apple apple orange  
    orange red blue green orange green blue  
    pirates ninjas cowboys ninjas pirates  
    

提交回复
热议问题