[Solved] about complicated RegExp [closed]


If you need to match string including only \w, - or . and not starting with ., then try this:

/^(?!\.)[\w.-]+$/

Details:

  • ^ – search from start of string
  • (?!\.) – don’t match if there is . symbol at this position
  • [\w.-]+ – match to more than 1 symbols from \w.- set
  • $ – match to end of string

Testing:

  • abc -> matched
  • ab_c -> matched
  • a-b_c. -> matched
  • a@-b_C. -> not matched
  • .a-b_c. -> not matched

3

solved about complicated RegExp [closed]