Search code examples
regexwordpresspreg-match

WordPress warning: preg_match(): Compilation failed: nothing to repeat at offset 1


Suddenly my friend's WordPress based website started showing up this warning on subpages:

Warning: preg_match(): Compilation failed: nothing to repeat at offset 1 in /wp-includes/class-wp.php on line 218

Lines 218/219 that are returned in the warning are as follows:

if ( preg_match("#^$match#", $request_match, $matches) ||
     preg_match("#^$match#", urldecode($request_match), $matches) ) {

Seems like the code is responsible for URL reworking.

Any ideas what could possibly be going wrong?


Solution

  • The error does not appear on the homepage but on sub-pages. Thus, I guess the permalinks structure is corrupt. An often suggested fix goes like this:

    1. temporary disable all your plugins! Do not skip this step.
    2. go to the WordPress admin dashboard: Settings -> Permalinks note what you have in the custom permalinks field somewhere else
    3. temporary switch to default permalinks. Save settings.
    4. check the page in question: are the preg_match errors gone?
    5. switch back to your previous custom permalinks setting
    6. re-enable back all the plugins, the pages should be back to normal.