我想在php中執行正則表達式。我想從$ str變量中選擇common_name = Bangladesh。我穿着我的正則表達式。正則表達式在這裏找不到任何匹配。我怎樣才能解決這個問題?php正則表達式找到兩個字符串之間的字符串
$str = "| conventional_long_name = People's Republic of Bangladesh | common_name = Bangladesh | image_flag = Flag of Bangladesh.svg";
$pat = "/(?=\common_name\s=).*?(?=\s\|)/";
if(preg_match($pat, $str, $matches)){
echo "Matches found";
echo $matches[0];
} else {
echo "No match found";
}
結果顯示
No match found
一號線你需要學習如何閱讀和調試錯誤消息分號。消息中包含解決問題所需的一切。 http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php – Anigel