0

I am looking for a single pcre (ver. 3.85) compatible regular expression that matches a string composed of three or more title case words but does not match any string containing words starting with lower-case letter. E.g.:

"Gaius Julius Caesar" should match
"Gaius Caesar" should not match
"Gaius Julius Caesar Rome" should match
"Gaius julius Caesar" should not match

Tried

(\b[A-Z]\w+\b){3,}

with no success.

Any hint?

George JL
  • 29
  • 5

2 Answers2

1

You could try the below pcregrep command,

$ pcregrep -o -M '^[A-Z]\w+(?: [A-Z]\w+){2,}$' file
Gaius Julius Caesar
Gaius Julius Caesar Rome

OR

Try the below command if the following chars after the starting uppercase letter must be in lowercase.

$ pcregrep -o -M '^[A-Z][a-z]+(?: [A-Z][a-z]+){2,}$' file
Gaius Julius Caesar
Gaius Julius Caesar Rome
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
0

Try one of these:

(\b[A-Z]\w+\b\s??){3,}

Here is the demo

(\b[A-Z]\w+\b)(\s+\b[A-Z]\w+\b){2,}

Here is the demo

friedi
  • 4,350
  • 1
  • 13
  • 19