Regular expression to find and remove duplicate words

前端 未结 9 936
孤城傲影
孤城傲影 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 09:52

    You won't be able to use regular expressions for this problem, because regex only matches regular languages. The pattern you are trying to match is context-sensitive, and therefore not "regular."

    Fortunately, it is easy enough to write a parser. Have a look at Per Erik Stendahl's code.

提交回复
热议问题