Home > Backend Development > PHP Tutorial > 如何查一个变量中含有连续的字母,全是大写或全是小写

如何查一个变量中含有连续的字母,全是大写或全是小写

WBOY
Release: 2016-06-13 13:32:13
Original
1068 people have browsed it

怎么查一个变量中含有连续的字母,全是大写或全是小写
$str = "ads放家里就发个lsd减肥爱上了对sdafgdsfghfdghjgfjghjgfhj方萨达浪费士大夫受到法律48955235萨达浪费撒地方老师地方就立即了解";
$p = "/\d{5}/i";

preg_match_all($p, $str, $result);
var_dump($result);
以上可以查到5位连续的数字,要是改成字母的话要怎么写正则,查看字母中(全是小写或是全是大写的连续的)位数不限


------解决方案--------------------
/[a-z]|[A-Z]+/ 或 /[a-z]/i
------解决方案--------------------
更正一下:/[a-z]+/i
上面是不区分大小写
/[a-z]+/
------解决方案--------------------
$p = "/[a-z]{5,}/i";
------解决方案--------------------
错了。这样试试。
$p = "/[a-z]{5,}|[A-Z]{5,}/";
------解决方案--------------------
楼主的"位数不限"是什么意思,可以是0,那就是:/[a-z]*/
------解决方案--------------------
全大写或全小写的话就是:/([a-z]*)|([A-Z]*)/
------解决方案--------------------
查看字母中(全是小写或是全是大写的连续的)位数不限
全是小写 /[a-z]+/
全是大写 /[A-Z]+/

没有肯定是不对的,所以不能是 *

------解决方案--------------------
$p = "/[A-z]+/";
A-z 匹配大小写英文
+ 出现次数大于等于1次

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template