正则瓜分字符

WBOY
Release: 2016-06-13 13:06:53
Original
875 people have browsed it

正则分割字符
字符串是
ul[class=xl xl2 cl] div.test ul[id=test]

我想用空格分割字符,但是[]号里面的空格不要分,单用正则可以实现这个功能吗?比如分之后,结果如下
ul[class=xl xl2 cl]
div.test 
ul[id=test]

如果正则无法实现,其他思路呢?

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

PHP code
$s = 'ul[class=xl xl2 cl] div.test sasa ul[id=test]';
preg_match_all('/\w+\[[^]]+]|[^\s]+/', $s, $r);
print_r($r); <div class="clear">
                 
              
              
        
            </div>
Copy after login
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!