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?

4

2 回答 2

1

您可以尝试以下 pcregrep 命令,

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

或者

如果开始大写字母后的以下字符必须为小写,请尝试以下命令。

$ pcregrep -o -M '^[A-Z][a-z]+(?: [A-Z][a-z]+){2,}$' file
Gaius Julius Caesar
Gaius Julius Caesar Rome
于 2014-10-11T10:14:17.487 回答
0

尝试其中之一:

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

这是演示

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

这是演示

于 2014-10-11T10:13:39.970 回答