使用首字母大写的连续单词的正则表达式

dag*_*da1 3 regex

我正在寻找一个正则表达式,可以在句子中识别句子中的连续单词以大写字母开头.

如果我们以下面的文字为例:

AZ集团是通过BDEC有限公司,英国国防设备目录出版商和英国国防工业指南为全球航空货运界以及国防和安全部门提供信息的长期市场领导者.

我希望能够检索以下内容:

AZ集团

BDEC有限国防设备

目录英国国防

工业防护产业

正则表达式甚至可以实现这一点吗?如果是这样,有人可以推荐吗?

nop*_*ole 9

(更新:我最初误解了你的问题.)

一个简单的例子就是

/([A-Z][\w-]*(\s+[A-Z][\w-]*)+)/
Run Code Online (Sandbox Code Playgroud)

如果存在不同语言结构的特殊情况,则可能需要进行修改.

ruby-1.9.2-p0 > %Q{The A-Z Group is a long-established market leader in the provision of information for the global air cargo community, and also for the defence and security sectors through BDEC Limited, publishers of the British Defence Equipment Catalogue and British Defence Industry Directory.}.scan(/([A-Z][\w-]*(\s+[A-Z][\w-]*)+)/).map{|i| i.first}

=> ["The A-Z Group", "BDEC Limited", "British Defence Equipment Catalogue", "British Defence Industry Directory"]