Jump to content

Different regular expression match result in PHP 7.4.11 and 7.4.12


Go to solution Solved by requinix,

Recommended Posts

I'm hoping someone might be able to explain to me why the following code produces different results in PHP 7.4.11 and 7.4.12. This is a simplified version of a real example from a project I'm working on. I can see that 7.4.12 moved to PCRE 10.35 but can't see any obvious reason why the below would behave differently.

<?php

preg_match('/([^\.]|^)\s*a/', "a", $matches);

var_dump($matches);

https://onlinephp.io/c/b56ca

  • Solution

Most of the time, when you find an oddity like this that can't be explained any other way, the answer is going to be a JIT thing: PCRE isn't supposed to, but occasionally does behave in slightly different ways when JIT is on or off.

ini_set("pcre.jit", 0);
preg_match('/([^\.]|^)\s*a/', "a", $matches);

But turning off JIT is not the best answer. Instead, do what kicken did and tweak the expression so it works.

Anyway, that expression really should work even with JIT enabled, so feel free to file a bug report against PCRE2 about it.
https://github.com/PCRE2Project/pcre2/issues

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.