I haven't encountered a PHP problem for a long time. This Regex problem takes a little time, and it is still the biggest backtracking and recursive restriction problem of the old problem. It is not difficult to modify the regular expressions with such problems after the learning is done. The main points are as follows. The template engine based on regular expression replacement is prone to the limit of maximum backtracking and recursion of regular expressions. The inertia matching is not terrible. under normal circumstances, the template is not enough, and the limit is often not exceeded. the discuz template engine is used in large quantities. However, if you don't pay attention to it or do not study it, you haven't encountered any PHP problems for a long time. This regular expression takes a little time, but it is still the biggest backtracking and recursive restriction problem of the old problem. It is not difficult to modify the regular expressions with such problems after the learning is done. The main points are as follows.
The template engine based on regular expression replacement can easily meet the maximum backtracking/recursion restrictions of regular expressions.
The inertia matching is not terrible. under normal circumstances, the template is not enough, and the limit is often not exceeded. the discuz template engine is used in large quantities. However, if you do not pay attention to or study, you may encounter errors and problems.
When preg _ * returns null, you must note that the function is is_null.
Errors are not terrible, but it is best to output all the errors so that debugging is easy.
In addition to the error cause, the matched text and the regular expression are also output, which makes debugging easy.
PHP code
References
1. 2010, Laruence "deep understanding of the maximum backtracking/recursion restrictions of regular expressions (pcre)"
2. 2011, PHP Chinese manual preg_last_error