Support » Plugin: iThemes Security » PHP Warning: preg_match(): Compilation failed

  • Hi,

    I have this PHP Warning looping in my log files, each day (I think it’s since 7.3 version but I’m not really sure):

    PHP Warning: preg_match(): Compilation failed: invalid range in character class at offset 29 in /wp-content/plugins/better-wp-security/core/modules/file-change/lib/package-factory.php on line 96

    Do you know what the problem is?

Viewing 3 replies - 1 through 3 (of 3 total)
  • It’s probably a php 7.3 incompatibility issue with the plugin.

    In php 7.3 PCRE (Perl Compatible Regular Expressions) has been updated to v2.

    PCRE is a library that PHP uses for dealing with Regular Expressions.

    PCRE2 is more strict in the pattern validations, so after php upgrade, some of the patterns that used to work may not compile anymore.

    Now there isn’t a regular expression pattern visible on line 96 in the package-factory.php file … but there is a regular expression being executed:

    95	if ( '@' === $search_path[0] ) {
    96		if ( ! preg_match( $search_path, $file ) ) {

    I’ve included the previous line as well in the code above, because it tells us what regex pattern to look for. One that starts with a @.
    There is only one match in the entire package-factory.php file:

    32 $core_files = '@' . preg_quote( ABSPATH, '@' ) . '[\w-_]+\.@';

    It’s the ‘[\w-_]+\.@’ part at the end where the problem is. The hyphen needs to be escaped. So it should be ‘[\w\-_]+\.@’.

    Make a backup copy of the current package-factory.php file. Make the edit as described above and then see whether the warnings in the log disappear.

    To prevent any confusion, I’m not iThemes.

    • This reply was modified 3 years, 7 months ago by nlpro.
    Thread Starter Julie Moynat


    Thank you for your answer!

    You were right, I have PHP 7.3 so I’ve tested your fix and it seems that it’s working. File change warnings are now working better.

    I’ve also noticed another PHP Warning but I don’t know if it’s a PHP 7.3 incompatibility as well:

    PHP Warning: printf(): Too few arguments in /wp-content/plugins/better-wp-security/core/modules/malware/settings-page.php on line 52

    I hope iThemes will fix these issues soon.

    Ok, great. Thanks for your confirmation. Naturally iThemes will need to fix this bug in a future release. It may take a while since iThemes does not monitor this forum.

    As to the other warning, you are probably using the WordPress Dashboard in a non English language (French I guess). So it’s basically a known translation issue (in the French translation of the iTSec plugin). So it’s not a bug in the plugin code.

    Since it’s a different issue please create a seperate topic.

    Oh (almost forgot) I guess this topic can be set to Resolved 😉

    • This reply was modified 3 years, 7 months ago by nlpro.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘PHP Warning: preg_match(): Compilation failed’ is closed to new replies.