這是字符串:$title = "享受 20% 折扣";這是在 % 的情況下不起作用的代碼$re = '~(?=(?:\S*[^\w\s]){2,})\S+~'; $str = "Get 20% Off== FG"; preg_match_all($re, $str, $matches);print_r($matches[0]);我想得到20%這個詞
1 回答

守候你守候我
TA貢獻1802條經驗 獲得超10個贊
嘗試這個:
$re = '(\d+(\.\d+)?%)';
$str = "Get 20% Off== FG";
preg_match_all($re, $str, $matches);
print_r($matches[0]);
輸出:
Array ( [0] => 20% )
- 1 回答
- 0 關注
- 155 瀏覽
添加回答
舉報
0/150
提交
取消