I am trying to construct a regex statement that matches a string conforming to the following conditions:
- 3-63 lowercase alphanumeric characters, plus "." and "-"
- May not start or end with . or -
- Dashes and periods cannot be adjacent to each other.
abc-123.xyz <- should match
abc123-.xyz <- should not match
I have been able to put this regex together, but it does not catch the third requirement. I've tried to use another negative lookahead/lookbehind,[i.e. - (?!.-|-.) ] but its still matching the strings with adjacent periods and dashes. Here's the regex statement I came up with that fulfills conditions 1 & 2:
^(?!\.|-)([a-z0-9]|\.|-){3,63}(?<!\.|-)$
FYI, this regex is for validating input when specifiying an AWS S3 bucket name in a CloudFormation template.