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
- minimum 3 letters
- followed optional - or _
- sequence of number 1 , 2 can repeated infinite times
- 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
Post a Comment