Removing duplicates in a comma-separated list with a regex?

前端 未结 5 1518
滥情空心
滥情空心 2020-12-18 07:45

I\'m trying to figure out how to filter out duplicates in a string with a regular expression, where the string is comma separated. I\'d like to do this in javascript, but I\

5条回答
  •  眼角桃花
    2020-12-18 08:18

    Here's a example:

    s/,([^,]+),\1/,$1/g;
    

    Perl regex substitution, but should be convertible to JS-style by anyone who knows the syntax.

提交回复
热议问题