regex - JavaScript Regular Expressions Special Characters -


why regular expression

/^[^-_]*([a-za-z0-9]{3,})+[-_]?[^-_]*$/i 

match on string?

,abc,,. 

it says string should contain of

  1. minimum 3 letters
  2. followed optional - or _
  3. sequence of number 1 , 2 can repeated infinite times
  4. no - or _ @ beginning or end of string

the regex should not allow other characters a-z, 0-9 , - or _, yet, allows them.

thanks in advance

erm, actually, says:

  • from start,
  • any number of characters not - or _ (matches ,)
  • catastrophically backtrack find @ least 3 alphanumerics (matches abc)
  • optionally match - or _ (matches nothing)
  • any number of characters not - or _ (matches ,,.)
  • to end.

did mean:

/^[a-z0-9]{3,}(?:[-_][12]+)?$/i 

correction, misunderstood "point 3".

/^[a-z0-9]{3,}(?:[-_][a-z0-9]{3,})*$/i 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -