PHP/PostGres 正则表达式仅在字符串中的单词有 2 个或更多大写且仅包含字母时匹配
这看起来是一个简单的表达,但我所有的修修补补都在某个地方失败了。我正在从 PostgreSQL 数据库中提取数据。我宁愿在 PostgreSQL 中进行过滤,但如果我需要在 PHP 中进行过滤,也可以。该列将有一个字符串,我需要搜索任何单词(由空格定义)具有两个或多个大写字母的匹配项。如果我需要分解每个字符串并单独解析“单词”,我也可以这样做,但似乎正则表达式会是更好的方法。
以下是一些示例:
“The Quick Brown”//不匹配
“QuicK Brown”//比赛(注意 QuicK 有 2 个大写字母)
“快速棕色”//比赛
"The QUICK1 Brown" //不匹配(QUICK 全部大写,但也有非字母字符)
"The QUICK BROWN1" //匹配,因为 QUICK 很受欢迎,尽管 BROWN1 不是。
“快速棕色”//不匹配
"The QUICK-BROWN" //不匹配(因为 - 不是字母,单词仅由空格定义)
“快速棕色”//不匹配
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过 http://regexr.com?2sdi4 检查
Checked via http://regexr.com?2sdi4