- Code, Content, and Presentation
-- PHP Server Side Scripting
---- Regex pattern cannot start or end with hyphen
- 4:39 am on Aug 24, 2013
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.
Personally, in PHP I don't know if I'd use a regex for the whole thing.
I think I'd perform some "quick checks" and then use a regex if the checks passed.
// do what I want here
Thanks to Lucy24 for pointing out the parallel thread here.
Brought to you by