preg_last_error 正则匹配错误
最后更新于:2022-04-02 02:29:26
[TOC]
## preg_last_error
最近一次的正则匹配错误
```
preg_match('/(?:\D+|<\d+>)*[!?]/', 'foobar foobar foobar');
if (preg_last_error() != PREG_NO_ERROR) {
switch (preg_last_error()) {
case PREG_INTERNAL_ERROR:
echo "PREG_INTERNAL_ERROR";
break;
case PREG_BACKTRACK_LIMIT_ERROR;
echo "PREG_BACKTRACK_LIMIT_ERROR";
break;
case PREG_RECURSION_LIMIT_ERROR;
echo "PREG_RECURSION_LIMIT_ERROR";
break;
case PREG_BAD_UTF8_ERROR;
echo "PREG_BAD_UTF8_ERROR";
break;
case PREG_BAD_UTF8_OFFSET_ERROR;
echo "PREG_BAD_UTF8_OFFSET_ERROR";
break;
}
}
// output:
// PREG_BACKTRACK_LIMIT_ERROR
```
';