PHP Warning: preg_match_all(): Compilation failed: unrecognized character after (?< at offset 1

While using preg_match_all function in php, i came across this issue of Compilation Failed.

On executing

preg_match_all('/<div>(?<product>.*)</li>/sU', $body, $matches)

I got the following error:

PHP Warning:  preg_match_all(): Compilation failed: unrecognized character after (?< at offset 32 in …

This is probably you are having old version of pcre (for me it was 6.6-6) which needs to be updated to 8.0 or higher.

Default CentOS Repositories dont have the latest version, for this you can use Utter Ramblings yum repository

Steps to Add the Utter Ramblings yum repository

Create a file /etc/yum.repos.d/utterramblings.repo and paste the following:-

[utterramblings]
name=Jason’s Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka

#then run

sudo yum --enablerepo=utterramblings install pcre

Thats it, just in case you get some error messages as:-

Transaction Check Error:

file /usr/share/man/man1/pcretest.1.gz from install of pcre-8.02-1.jason.1.x86_64 conflicts with file from package pcre-6.6-6.el5_6.1.i386

then it might be because your system is 64 bit and you need to remove i386 version of lib, to fix it run

sudo yum remove pcre-6.6-6.el5_6.1.i386
sudo yum --enablerepo=utterramblings install pcre

One comment on “PHP Warning: preg_match_all(): Compilation failed: unrecognized character after (?< at offset

  1. Reply Mike Oct 30,2013 12:20 pm

    Thank you very helpful article. I did the removal first before your steps.

    # search for existing
    rpm -q –queryformat “%{name}.%{arch}\n” pcre

    pcre.x86_64
    pcre.i386

    # Remove all existing pcre using –nodeps
    rpm -ev –nodeps pcre.x86_64
    rpm -ev –nodeps pcre.i386

    # did your steps

    # Then restarted web service and checked phpinfo

Leave a Reply