1

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 %

0

1 Answer 1

1
^(?!\.)([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

Sign up to request clarification or add additional context in comments.

4 Comments

almost fine, but now I can not put one char, and '.' (dot) is allowed on the end - shouldn't be
previously looked better, when we use '+' then one character is not allowed. Code above not working.
@Jatuzo for javascript use ^(?!\.)([A-Za-z0-9\.\$[]_\-])*[A-Za-z0-9\$[]_\-]$
for now nothig allowed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.