我目前试图在PHP中的空字符串上获得匹配,这个当前运行应该匹配not
和空''
,但我似乎只能得到它匹配not
出于某种原因?有人能告诉我我做错了什么吗?字边界匹配空字符串
preg_match('/^\bnot|$/', 'not', $matches);
print_r($matches); // array(0 => 'not') // correct
preg_match('/^\bnot|$/', '', $matches);
print_r($matches); // array(0 => '') // maybe right ?
preg_match('/^\bnot|$/', 'foo', $matches);
print_r($matches); // array(0 => '') // deff messed up
您究竟想在这里匹配什么?在主题开始之后的单词边界是多余的;为什么不只是'如果($ str =='不')'?或者应该以'not'开始? –