Home  >  Article  >  Backend Development  >  正则匹配这样一段字符

正则匹配这样一段字符

WBOY
WBOYOriginal
2016-06-20 12:28:39954browse

有个需求,需要匹配固定格式的字符串:
亮点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 "
";/*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 "
";/*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        ))*/


谢谢!!!
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
Previous article:Laravel Forms 使用Next article:php中cookie和session的问题