Search code examples
regexpcregrep

Matching 3+ Title Case Word in a single pcre expression


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?


Solution

  • 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