正则表达式—匹配连续重复的字符


<?php

header("Content-Type:text/html;charset=utf-8");

$str = '开开开开开不不不起';

$reg = '/[\x{4e00}-\x{9fa5}]{5}/u';

preg_match($reg,$str,$match);

 

 

 

$str = '开不开开开开开不不不起';

$reg = '/[\x{4e00}-\x{9fa5}]{5}/u';        //开不开开开

preg_match($reg,$str,$match);

var_dump($match);

die;

 

//需求:筛选出连续出现5次的字符 开开开开开

$str = '开不开开开开开不不不起';

$reg = '/([\x{4e00}-\x{9fa5}])\1{4}/u';        //开\1{4} --->     开开{4}

//\1引用的是第一个小组的内容

//\2引用的是第二个小组的内容

//..    

preg_match_all($reg,$str,$match);

var_dump($match);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM