현재 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
여기 정확히 일치시키려는 대상은 무엇입니까? 당신의 주제의 시작 다음 낱말 경계는 불필요하다; 왜'if ($ str == 'not')'가 아닌가? 아니면 문자열이 'not'으로 시작해야합니까? –