Reputation: 328
This is my regex
^(?![^a-z])(?!.*\.\.)[a-z0-9._]+([a-z])$
Rules
String should start and end with [a-z]
double . in a row is not allowed
double _ in a row is allowed ( should be not this is wrong)
Allowed characters are [a-z0-9_.]
everything works as like what i want, but i cannot restrict 2 o more _ in a row it has same restrict for . but does not work for _
This is online editor: https://regex101.com/r/XJXlpS/2
what is wrong ?
Upvotes: 1
Views: 44
Reputation: 784938
You can use this regex:
/^(?![^a-z])(?!.*([_.])\1)[\w.]*[a-z]$/gmi
RegEx Breakup:
^
: Start(?![^a-z])
: Make sure first char is a letter(?!.*([_.])\1)
: Make sure we don't have repeated underscore or dot[\w.]*
: Match 0+ word characters or dot[a-z]
: Match a letter in the end$
: EndUpvotes: 1