'RegEx minimum 4 characters with no repetition
Trying to create a regex where a field should contain minimum 4 characters(only alphabets [a-zA-Z]) where
- first 4 alphabets should not repeat. eg aaaa,zzzz not acceptable
- first 4 characters should not contain space, numbers, special characters
- afterwhich anything is fine
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!@#$&()\-`.+,"]
Solution 1:[1]
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 line
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
