views:

18

answers:

1

This seems like a simple expression, but all of my tinkering has failed in one place or another. I am pulling data out of a PostgreSQL database. I would rather filter in PostgreSQL, but if I need to do it in PHP that is fine too. The column will have a string, and I need to search for matches where any word (defined by spaces) has two or more capital letters. If I need to just explode each string and parse the "words" individually, I can do that too, but it seems like a regexp would be a much better way.

Here are some examples :

"The Quick Brown" //No Match

"The QuicK Brown" //MATCH (note QuicK has 2 caps in it)

"THE QUICK BROWN" //Match

"The QUICK1 Brown" //No Match (QUICK is all caps, but it has a non alpha character too)

"The QUICK BROWN1" //Match because QUICK is a hit even though BROWN1 is not.

"tHe qUick bRown" //No Match

"The QUICK-BROWN" //No Match (because - is non alpha, and words are only defined by space)

"the quick brown" //No Match

A: 
(^| )[A-Za-z]*[A-Z][A-Za-z]*[A-Z][A-Za-z]*( |$)

Checked via http://regexr.com?2sdi4

Wernight