Home > OS >  Regex 4 characters and 1 space minimum anywhere position
Regex 4 characters and 1 space minimum anywhere position

Time:12-16

I've tried this

(?!\sa-zA-Z){4,}\s{1,}

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.

  • Related