PHP搜索字符串中的大写+小写混合单词? [英] PHP to SEARCH the Upper+Lower Case mixed Words in the strings?

查看:41
本文介绍了PHP搜索字符串中的大写+小写混合单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有一个字符串:

A quick brOwn FOX called F. 4lviN

我想要搜索的单词必须具备以下条件:

The WORDS i want TO SEARCH must have the following conditions:

  • 包含 MIXED Upper & 的单词小写
  • 仅包含字母 A 到 Z (A-Z a-z)
    (例如:没有数字、没有逗号、没有句号、没有破折号等)

所以假设,当我搜索(例如在这个字符串中)时,搜索结果将是:

So suppose, when i search (for e.g in this string), the search result will be:

brOwn

因为它是唯一一个同时包含Upper &里面的小写字母(也只包含字母).

那么我怎样才能让它在 php 中工作呢?

Because it is the only word which contains both of Upper & Lower Case letters inside (and also containing only alphabets).

So how can I make it work in php?

推荐答案

你应该擅长:

preg_match_all("/\b([a-z]+[A-Z]+[a-zA-Z]*|[A-Z]+[a-z]+[a-zA-Z]*)\b/", $input, $matches);
print_r($matches[1]); 

<小时>

因为不需要捕获,所以也可以>>


As capturing is not needed, it can be also >>

preg_match_all("/\b(?:[a-z]+[A-Z]+[a-zA-Z]*|[A-Z]+[a-z]+[a-zA-Z]*)\b/", $input, $matches);
print_r($matches[0]); 

这篇关于PHP搜索字符串中的大写+小写混合单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆