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