Reputation: 3
Trying to create a regex where a field should contain minimum 4 characters(only alphabets [a-zA-Z]) where
I tried following expression but 1 case is failing which is (a123,a@#!): ^(?=.{1,4}$)(([a-zA-Z]){1,4}\2?(?!\2))+[a-zA-Z0-9!@#$&()\-`.+,"]
Upvotes: 0
Views: 67
Reputation: 163517
You might write the pattern as:
^(?!(.)\1{3})[a-zA-Z]{4}.*
Explanantion
^
Start of string(?!(.)\1{3})
Negative lookahead, assert not 4 of the same characters[a-zA-Z]{4}
Match 4 chars a-z A-Z.*
Match the rest of the lineUpvotes: 1