Reputation: 13
I need write regular expression which will handle below constraints:
Names can contain only letters, numbers, hyphens (-), dollar signs, brackets ([ , ]), and underscores (_). Single periods (.) are allowed only inside of an internal name (abc.de), not at the beginning or the end of an internal name (.abc or def.). Spaces and all other special characters not listed here are not supported.
I wrote something like this:
(^[^\.])([A-Za-z0-9\.\$\[\]\_\-])*[^.]
but still I can put one sign like: ! or @ or %
Upvotes: 1
Views: 42
Reputation: 67968
^(?!\.)([A-Za-z0-9\.\$\[\]\_\-])+(?<!\.)$
You need anchors
.Also [^\.]
can accept anything other than .
.So lookaheads and lookbehinds are advised.
See demo.
https://regex101.com/r/sJ9gM7/78
Upvotes: 1