正则匹配这样一段字符

WBOY
Release: 2016-06-20 12:28:39
Original
942 people have browsed it

有个需求,需要匹配固定格式的字符串:
亮点1:aaaaaa;亮点2:bbbbbb;亮点3:cccccc;
冒号和分号都是中文字符,亮点最少有一个(比如亮点A:哈哈;)
格式是必须有冒号和分号,左边的文字不一定是“亮点”,也可能是其他文字,最多15个字。
快下班了,求解答、、、、、谢谢


回复讨论(解决方案)

$str = '亮点1:aaaaaa;亮点2:bbbbbb;特色:cccccc;';preg_match_all('/(.+?):(.+?);/',$str,$m);echo "<pre class="brush:php;toolbar:false">";print_r($m);echo "
Copy after login
Copy after login
";/*Array( [0] => Array ( [0] => 亮点1:aaaaaa; [1] => 亮点2:bbbbbb; [2] => 特色:cccccc; ) [1] => Array ( [0] => 亮点1 [1] => 亮点2 [2] => 特色 ) [2] => Array ( [0] => aaaaaa [1] => bbbbbb [2] => cccccc ))*/

$str = '亮点1:aaaaaa;亮点2:bbbbbb;特色:cccccc;';preg_match_all('/(.+?):(.+?);/',$str,$m);echo "<pre class="brush:php;toolbar:false">";print_r($m);echo "
Copy after login
Copy after login
";/*Array( [0] => Array ( [0] => 亮点1:aaaaaa; [1] => 亮点2:bbbbbb; [2] => 特色:cccccc; ) [1] => Array ( [0] => 亮点1 [1] => 亮点2 [2] => 特色 ) [2] => Array ( [0] => aaaaaa [1] => bbbbbb [2] => cccccc ))*/


谢谢!!!
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!