Regex 'or' operator avoid repetition

后端 未结 4 2302
轮回少年
轮回少年 2021-02-20 03:16

How can I use the or operator while not allowing repetition? In other words the regex:

(word1|word2|word3)+

will match wo

4条回答
  •  生来不讨喜
    2021-02-20 03:42

    Byers' solution is too hard coded and gets quite cumbersome after the letters increases.. Why not simply have the regex look for duplicate match?

    ([^\d]+\d)+(?=.*\1)
    

    If that matches, that match signifies that a repetition has been found in the pattern. If the match doesn't work you have a valid set of data.

提交回复
热议问题