This is a regex where string must start and end with an alphanumeric character and can contain alphanumeric characters and dashes.
/^[a-zA-Z0-9]{1}[a-zA-Z0-9\-]+[a-zA-Z0-9]{1}$/
How can I make sure that the consecutive dashes are not allowed? for example:
should allow: some-string
should NOT allow: some--string
Thanks
Edit: I want to allow several dashes, just not consecutively. for example “some-thing-here” is OK, and “some–thing” is NOT.
No need for complicated patterns with optional dashes just use this:
See it here on Regexr
Start with at least one alphanumeric. Then there can be a dash followed by at least one alphanumerics 0 ore more times.