I am trying to fulfill the following restrictions:
- Line
- has 3 to 256 characters, which are az, 0-9, dashes, or periods.
- this line cannot begin or end -
I want to get the following result:
aaa -> good
aaaa -> good
-aaa -> bad
aaa- -> bad
A have some regular expressions that do not give the correct answer: 1) ^[^-][a-z0-9\-.]{3,256}[^-]$gives all test lines as bad;
2) ^[^-]+[a-z0-9\-.]{3,256}[^-]+$treats the first three lines as one matching line, since [^ -] matches the new line that I am assuming.
3) ^[^-]?[a-z0-9\-.]{3,256}[^-]?$(? For one or zero matching dashes) gives all test lines as good
Where is the truth? I feel it is either close to mine, or much more complicated.
PS I am using python 3 re module.