Home  >  Article  >  Backend Development  >  求正则表达式 计算字符串长度解决思路

求正则表达式 计算字符串长度解决思路

WBOY
WBOYOriginal
2016-06-13 13:25:26854browse

求正则表达式 计算字符串长度
$str = "asd你好[哈哈][你好][]"
计算符号包括里面[]的个数
$str长度应该是2个:[]符号里面没有内容不被计算
$strstr = "asd你好[哈哈][你好]"
长度也是2个

------解决方案--------------------

PHP code

preg_match_all("@\[.*?\]@",$strstr,$result);
echo count($result[0]) <div class="clear">
                 
              
              
        
            </div>
Statement:
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