I've tried this
(?!\sa-zA-Z){4,}\s{1,}
- I want 4 or more characters and minimum 1 space anywhere in string, but doesn't work
- The space can be anywhere position without from start. I've try this, but that not work Regex: Allow minimum alphanumeric, dot and - characters. Asterisk allowed anywhere?
EDIT: I would like this result : aa aa..., aaa a..., a aaa..., aaaa ...
CodePudding user response:
You can use
\b[a-zA-Z](?=[a-zA-Z ]{3})[a-zA-Z]* [a-zA-Z]*
Explanation
\b
A word boundary to prevent a partial word match[a-zA-Z]
Match a single char a-zA-Z(?=[a-zA-Z ]{3})
Positive lookahead, assert 3 of the listed chars in the character class to the right of the current position[a-zA-Z]* [a-zA-Z]*
Match optional chars a-zA-Z, then match 1 spaces space and again optional chars a-zA-Z
See a regex demo.