I am trying to build a regular expression with this criteria:
- Not start or end with these characters '-', '.', '_'
- The string must be between 4 to 8 length
Example of allowed strings:
- hello
- hellowor
- he_ll_ow
- he-ll.ow
Not allowed strings:
- -hello
- _hello
- .hello
- hello_
- toolongstringhere
- t
Currently, I have this expression:
Pattern.compile("^[^-_\\.](.*[^-_\\.])?$");
This is working for the allowed characters but when I tried to add the length the expression does not work anymore for the rule of the not allowed expressions at the end.