Home > Net >  REGEX how to repeat pattern
REGEX how to repeat pattern

Time:06-08

[a-z0-9-_] ?((\\D)|(\\W)|(\\S)|(\\H)|(\\B)|(\\Q)|(\\E))*

I want the pattern to reapeat ex:

valid : abc\D\Wabc, abc, \W, \Wabc, \E\D,\E\Dsd\B

for now only the regex order is valid

CodePudding user response:

You can validate them with

/^(?:[a-z\d_-]|\\[DWSHBQE])*$/
  • ^ Start of a string
  • (?: Non-capturing group
    • [a-z\d_-]|\\[DWSHBQE] Match one of lowercase letters, digits, - and _. Or, \ and one of D, W, S, H, B, Q, E
  • ) Close non-capturing group
  • * The previous match zero or more times
  • $ End of a string

Also, see the demo

  • Related