Reputation: 125
I'm looking for regex that matches this pattern:
/word-word-word/ MATCH
/word-word/ DO NOT MATCH
/word/ DO NOT MATCH
Starts with /, 3 words in a row, with 2 dashes in between, ends with /
This is what I have so far, but it doesn't work.
\/^[A-Za-z]+([-][A-Za-z]+)+([-][A-Za-z]+)$\/
Upvotes: 1
Views: 70
Reputation: 2738
Starts with /, 3 words in a row, with 2 dashes in between, ends with /
But you are using \/^[A-Za-z]+([-][A-Za-z]+)+([-][A-Za-z]+)$\/
Which means start of string should be word but there should be a /
before it. It's a paradox.
Those slashes should come inside anchors. Also you don't need [ ]
for -
since it's a single character.
Regex: ^\/[a-zA-Z]+-[a-zA-Z]+-[a-zA-Z]+\/$
Upvotes: 4