Redd. Lowercase letters and hyphens

Can someone help me write a regex that matches only all lowercase letters plus a hyphen.

Example: this-page-name

+5
source share
2 answers

This will cause 1 or more characters, which are either lowercase az or hyphen

[a-z\-]+

The trick is to avoid a backslash hyphen.

For completeness, you can add an appropriate border, such as \ b at each end, to indicate complete coincidence of words, or ^ and $ so that it matches the complete line.

+12
source

Sample Mike Clark [a-z\-]+will match-start-dash-double-dash---and-end-dash-

Maybe a ^[a-z]+(-[a-z]+)*$little more accurate.

+6
source

All Articles