我需要一个正则表达式,它会在字符串中搜索任何包含3个或更多大写字母的单词,我需要它来返回整个单词。
答案 0 :(得分:1)
使用此正则表达式:
/\b[a-z]*[A-Z][a-z]*[A-Z][a-z]*[A-Z][A-Za-z]*\b/
经过测试(使用Ruby):
irb:001> re = /\b[a-z]*[A-Z][a-z]*[A-Z][a-z]*[A-Z][A-Za-z]*\b/
#=> /[a-z]*[A-Z][a-z]*[A-Z][a-z]*[A-Z][A-Za-z]*/
irb:002> s = "The foo FooBar FooBarBaz ABC xABC ABCx aLongerTestWordHere said hi"
#=> "The foo FooBar FooBarBaz ABC xABC ABCx aLongerTestWordHere said hi"
irb:003> s.scan(re)
#=> ["FooBarBaz", "ABC", "xABC", "ABCx", "aLongerTestWordHere"]