我想在 php 中执行一个正则表达式。我想从 $str 变量中选择 common_name = Bangladesh 。我穿着我的正则表达式。正则表达式在这里找不到任何匹配项。我怎样才能解决这个问题?
$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