Error with Php and Preg_Match

1

I have the following line in a php file

if(preg_match("!\oa!", $id)){

Until about 2 months ago this worked normally but started to give this error

  

Warning: preg_match () [function.preg-match]: Compilation failed:   missing opening brace after \ o at offset

Can anyone tell me what's going on? I used some regular expression validators online and did not return any errors.

    
asked by anonymous 15.10.2016 / 01:34

1 answer

1

It's probably a bug in the PCRE library version you use , upgrade to the latest version.

As can be seen in the changelog , item 32 :

  
  • Error messages for syntax errors following \g and \k were giving inaccurate offsets in the pattern.
  •   

    The error can be seen in this example that uses version 8.35:

    echo PCRE_VERSION; // 8.35 2014-04-04
    
    var_dump(preg_match('/\k/', 'foo')); 
    // \k is not followed by a braced, angle-bracketed, or quoted name at offset 2
    
    var_dump(preg_match('/\g/', 'foo')); 
    //  a numbered reference must not be zero at offset 1
    

    An alternative is to escape \k , \g and in your case \o with a double inverse bar \ :

    $id = "\oa";
    
    if(preg_match("!\\oa!", $id)) {
        echo "Match!";
    } else {
        echo "No match.";
    }
    

    See DEMO

        
    15.10.2016 / 02:42