Home  >  Article  >  Backend Development  >  一个待匹配的字符串中有多个符合正则表达式的字符串段,怎么能将之分别匹配出来

一个待匹配的字符串中有多个符合正则表达式的字符串段,怎么能将之分别匹配出来

WBOY
WBOYOriginal
2016-06-13 12:55:47930browse

一个待匹配的字符串中有多个符合正则表达式的字符串段,如何能将之分别匹配出来
举例:

正则表达式: 1.+2

待匹配的字符串   31326451226476142345

希望能匹配出来
132
12
142

而非
132
13264512
132645122
1326451226476142
12
122
...


我用preg_match_all()貌似就会得出上述不想要的结果

求教


------解决方案--------------------
$s='31326451226476142345';<br />
preg_match_all('/1.*2/U',$s,$m);<br />
print_r($m);

Array
(
    [0] => Array
        (
            [0] => 132
            [1] => 12
            [2] => 142
        )

)
------解决方案--------------------
楼上对的,加个大U反贪懒
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