Regex for words formed with specific characters

前端 未结 1 2002
天命终不由人
天命终不由人 2020-12-19 23:21

I am looking for a regex to match words formed with specific characters without repeating any character: Example, for a b c and d, how to specify a regex to match those stri

相关标签:
1条回答
  • 2020-12-19 23:43

    You can use this regex based on negative lookahead:

    ^(?:([abcd])(?!.*\1)){1,4}$
    

    RegEx Demo

    Breakup:

    ^            Line start
    (?:          Start non-capturing group
      ([abcd])   Match a or b or c or d and group it 
      (?!.*\1)   Negative lookahead to fail the match if same grouped char is ahead
    ){1,4}       1 to 4 occurrences of non-capturing group
    $            Line end
    
    0 讨论(0)
提交回复
热议问题