1.2.798. 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.798.1. Suggestions

  • Fix the regex by adding regex delimiters

1.2.798.2. Specs

Short name

Structures/NoEmptyRegex

Rulesets

All, Analyze, CE, CI-checks

Exakat since

0.11.1

PHP Version

All

Severity

Critical

Time To Fix

Quick (30 mins)

Precision

Very high

Features

class

Examples

Tikiwiki

Available in

Entreprise Edition, Community Edition, Exakat Cloud