Menu

← Back to regexp.*

Error Identifier: regexp.pattern

Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.

Code example #

<?php declare(strict_types = 1);

$result = preg_match('/[unclosed/', 'test');

Why is it reported? #

The regular expression pattern passed to a preg_* function is invalid and would produce a warning or error at runtime. PHP’s PCRE engine cannot compile the pattern, which means the function call will fail. PHPStan validates regex patterns at analysis time when they can be statically resolved.

Common causes include missing closing delimiters, unmatched brackets, invalid escape sequences, and other PCRE syntax errors.

How to fix it #

Correct the regular expression syntax:

 <?php declare(strict_types = 1);
 
-$result = preg_match('/[unclosed/', 'test');
+$result = preg_match('/\[unclosed/', 'test');

Or if the intent was a character class, close the bracket:

 <?php declare(strict_types = 1);
 
-$result = preg_match('/[unclosed/', 'test');
+$result = preg_match('/[unclosed]/', 'test');

Test the corrected pattern using a tool like regex101 to verify it matches the intended strings before applying the fix.

How to ignore this error #

You can use the identifier regexp.pattern to ignore this error using a comment:

// @phpstan-ignore regexp.pattern
codeThatProducesTheError();

You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:

parameters:
	ignoreErrors:
		-
			identifier: regexp.pattern

Rules that report this error #

  • PHPStan\Rule\Nette\RegularExpressionPatternRule [1] phpstan/phpstan-nette
  • PHPStan\Rules\Regexp\RegularExpressionPatternRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.