Forum Moderators: coopster
/^[a-z0-9]{1}[a-z0-9]{0,254}?!-$/
that wouldn't match the string "abc"
i think you can put a quantifier on a capturing group
(([a-z0-9]+-)*[a-z0-9]+){1,255} ^.{1,255}$ or ^[a-z0-9-]{1,255}$ ^([a-z0-9]+-)*[a-z0-9]+$ doesn't match when there is NO hyphen. Making the hyphen optional will make the pattern very ambiguous. ^[a-z0-9][a-z0-9-]*}$ AND ^[a-z0-9-]{1,255}$ AND !-$ ^[a-z0-9][a-z0-9-]*[a-z0-9]$ AND ^[a-z0-9-]{2,255}$ if there are no "one character" requests. doesn't match when there is NO hyphen
^[a-z0-9][a-z0-9-]*}$
[a-z0-9-]{1,255}
^[a-z0-9][a-z0-9-]*$ AND ^[a-z0-9-]{1,255}$ AND !-$ ^[a-z0-9][a-z0-9-]*$ ^[a-z0-9-]{1,255}$ !-$^([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])$ to allow for one character non-hyphen strings, two character non-hyphen strings, or an unlimited number of character strings that do not begin or end with a hyphen.
(^-|--|-$) and ^[a-z0-9-]{1,255}$ together I can test that:$path = $_GET['path'];
if(preg_match('/(^-|--|-$)/', $path) || !preg_match('/^[a-z0-9-]{1,255}$/', $path)){
header('HTTP/1.0 404 Not Found');
die();}
!(^|-)-|-$ or !^-|-($|-) to work for me. I'm sure it's because I'm poorly implementing them in the script above.
So using (^-|--|-$) and ^[a-z0-9-]{1,255}$ together
I'm having difficulty writing the regex for this pattern:
A string must be between 1 to 255 characters in length.
A string can only contain a-z, 0-9, or a hyphen.
A hyphen cannot follow another hyphen.
A string cannot start or end with a hyphen.