I have created this regular expression to validate usernames which I need in my projects:^(?=.{3,32}$)(?!.*[._-]{2})(?!.*[0-9]{5,})[a-z](?:[\w]*|[a-z\d\.]*|[a-z\d-]*)[a-z0-9]$It works just fine. But I'm wondering if there is any improvement and optimization for it, since I'm not exactly a regex-guy.The regex and tests are available here.Rules are:usernames should start with [a-z]usernames should end with [a-z0-9]usernames can have a length between 3 and 32usernames can contain any of [a-z0-9\._-]Numbers should not be in the vicinity of each other more than 4 times. I mean p1234 is a match and p12345 is not.each username can contains only one of [\._-]. I mean a username can contain . or - or _each ., -, and _ should be followed by an alpha-numeric. I mean a . can not be followed by another .. They should not be in the vicinity of each other.Tests:j1vad-amiry            matchj1vad-ami-ry           matchja23d_am8ry            matchja_23d_am8ry           matchjav5d2.am3y            matchjav.ad.amiry           matchjav.ad.ami.ry.2        matchja3fd4                 matchpage2491               matchpage24915              not matchjav-ad_amiry           not matchjavad_am-iry           not matchjav.ami-ry             not matchjav.ami_ry             not matchjav.ami__ry            not match2jav                   not match2jav_ad                not match2jav_ad3               not match
Optimizing and improving a username regex
c#;optimization;regex