Regex not start with dot or end with dot

python, regex

Solution

From your previous question, you should be able to use:

^[^.].*[^-_.]$

But if you want to be able to match a 1 character string, you will need negative lookaheads:

^(?![.])(?!.*[-_.]$).+

And if you want to match empty strings too, simply use `*` instead of `+`.

^(?![.])(?!.*[-_.]$).*

Problem

I need a regular expression that does not start with a dot or end with `[-_.]`. This regex works but fails for the first condition; it does not start with dot: ``` ^[A-Za-z0-9][^.]*[^-_.][A-Za-z0-9]$ ``` For example: `test.com` should be a valid string but it fails.

Original source