Reputation: 1748
I recently had test with regex, but I am not skilled in it. I try to write something for pattern:
I wrote somethin like this "(^[a-zA-Z]).(/w{6,16}).*(?<!-)$"
, ofcourse it is not correct and not full.
I am very interesting in correct answear with explanaition, you could downvote my question if you think, it shoud be.
Upvotes: 1
Views: 28
Reputation: 626699
You may use
^[a-zA-Z](?=.{5,15}$)[^-]*(?:-[^-]+)?$
See the regex demo
Details
^
- start of string[a-zA-Z]
- an ASCII letter(?=.{5,15}$)
- a positive lookahead requiring 5 to 15 chars up to the string end from the current position[^-]*
- (a negated character class) 0+ chars other than -
(?:-[^-]+)?
- an optional non-capturing group that matches 1 or 0 repetitions of
-
- a hyphen[^-]+
- 1+ chars other than -
$
- end of stringUpvotes: 1