Regex not start with dot or end with dot
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 +
.
^(?![.])(?!.*[-_.]$).*
Using negative lookaheads to assert your requirements for the string:
^(?!^\.)(?!.*[-_.]$)[a-zA-Z0-9]+$
- First character not a "."
- Last character not a "-", "_", or "."
- Also at least one character in length