B. Christophe
B. Christophe

Reputation: 89

Regex 4 characters and 1 space minimum anywhere position

I've tried this

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

EDIT: I would like this result : aa aa..., aaa a..., a aaa..., aaaa ...

Upvotes: 3

Views: 159

Answers (1)

The fourth bird
The fourth bird

Reputation: 163527

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.

Upvotes: 3

Related Questions