PHP中的正则表达式实例详解(2)

instead of specifying the order that things should appear, it's saying that it must appear but we're not worried about the order.
The first grouping is (?=.{8,}). This checks if there are at least 8 characters in the string. The next grouping (?=.[0-9]) means "any alphanumeric character can happen zero or more times, then any digit can happen". So this checks if there is at least one number in the string. But since the string isn't captured, that one digit can appear anywhere in the string. The next groupings (?=.[a-z]) and (?=.[A-Z]) are looking for the lower case and upper case letter accordingly anywhere in the string.

$str= "HelloWorld2016"; if (preg_match("/^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/", $str,$arr)){ print_r($arr); }

向后查找 ?<=

?<= 表示假如匹配到特定字符,则返回该字符后面的内容。
?= 表示假如匹配到特定字符,则返回该字符前面的内容。

$str = 'chinadhello'; $preg = '/(?<=a)d(?=h)/'; preg_match($preg, $str, $arr); print_r($arr);

好了,今天的教程就先到这里,有什么问题大家可以留言,我们来讨论下

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/3d730adbb312ad21e54304761daed4d0.html