将 PHP 的 eregi 转换为 preg_match


convert PHP's eregi to preg_match

我不知道如何修复此错误

 Warning: preg_match(): Unknown modifier '[' in 

我的代码是

while(list($k,$v)=each($con2)) {
    $patt="($this->block_start_word|$this->block_end_word)[[:blank:]]*([0-9a-zA-Z'_]+)[[:blank:]]*$this->block_end_delim(.*)";
    if (eregi($patt,$v,$res)) {

我想将 eregi 的 php 版本更新到 preg_match 我试试这个

hile(list($k,$v)=each($con2)) {
    $patt="($this->block_start_word|$this->block_end_word)[[:blank:]]*([0-9a-zA-Z'_]+)[[:blank:]]*$this->block_end_delim(.*)";
    if ( preg_match($patt,$v,$res)) {

您忘记了正则表达式的分隔符,因此只需更改以下内容:

if ( preg_match($patt,$v,$res)) {

自:

if ( preg_match("/" . $patt . "/",$v,$res)) {