ruby - Regex dismatch repeat special character -


i'm doing regex check slug. regex : /^[^-][a-z\-].*[^-]+$/

here's i'm checking right :

my-awesome-project => valid

-my-awesome-project => invalid

my-awesome-project- => invalid

now want check if dash repeating or not :

my-awesome-project => should valid

my-awesome--project => should not valid

my----awesome-project => should not valid

can regex ?

thank you,

i think regexp should work:

/^[a-z]+(-[a-z]+)*$/ 

what does: ^[a-z]+ matches if string begins @ least on character. after there may (-[a-z]+)*$ 0 or more occurances of dash followed again @ least 1 character.

see on rubular.


Comments

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -