1.2.806. No Empty Regex¶
PHP regex don’t accept empty regex, nor regex with alphanumeric delimiter.
Most of those errors happen at execution time, when the regex is build dynamically, but still may end empty. At compile time, such error are made when the code is not tested before commit.
<?php
// No empty regex
preg_match('', $string, $r);
// Delimiter must be non-alphanumerical
preg_replace('1abc1', $string, $r);
// Delimiter must be non-alphanumerical
preg_replace('1'.$regex.'1', $string, $r);
?>
See also PCRE and Delimiters.
1.2.806.1. Connex PHP features¶
1.2.806.1.1. Suggestions¶
Fix the regex by adding regex delimiters
1.2.806.1.2. Specs¶
Short name |
Structures/NoEmptyRegex |
Rulesets |
|
Exakat since |
0.11.1 |
PHP Version |
All |
Severity |
Critical |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Examples |
|
Available in |