Regular Expressions 101

Community Patterns

words without special characters and allow words to be separated by a dash sign

0

Regular Expression
ECMAScript (JavaScript)

/
^([\w\d]+)((?:([\s]{0,1}-[\s]{0,1}|\s)([\w\d])+){0,1})+$
/
gm

Description

This regular expression checks for below rules:

  • Must not have special characters except a dash sign
  • Must not start with a dash sign or white space
  • Must not end with a dash sign or white space
  • Must not have a dash sign or white space in sequence
Submitted by Vijay sasvadiya - 3 years ago