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

<?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);

原文地址:https://www.cnblogs.com/lovebing/p/7681409.html