0
如何執行preg_match
這執行預浸比賽
$needle = '"pid": "20"';
$haystack = '"pid": "1"' . '"pid": "12"' . '"pid": "20"' . '"pid": "14"';
,並順便把針數值也不是一成不變的
我是新手在preg_match
如何執行preg_match
這執行預浸比賽
$needle = '"pid": "20"';
$haystack = '"pid": "1"' . '"pid": "12"' . '"pid": "20"' . '"pid": "14"';
,並順便把針數值也不是一成不變的
我是新手在preg_match
[0-9]+ // Matches 1 or more numbers from 0 to 9
這是正是什麼你問過,但如果你提供了你期望的結果或者你如何收到你的乾草堆,那麼可能會有比正則表達式更合適的解決方案。
$needle = '/"pid": "[0-9]+"/';
$haystack = '"pid": "1"' . '"pid": "12"' . '"pid": "20"' . '"pid": "14"';
preg_match_all($needle,$haystack,$matches);
$matches
輸出
(
[0] => Array
(
[0] => "pid": "1"
[1] => "pid": "12"
[2] => "pid": "20"
[3] => "pid": "14"
)
)
要了解更多關於正則表達式,check out this basic syntax reference。
更好地匹配0或PID串空間,以便使用您正則表達式是這樣的:
$needle = '/"pid"\s*:\s*"\d+"/';