Bug #81537 [Com]: Error in regular expression using negation.

From: Date: Wed, 09 Aug 2023 14:34:27 +0000
Subject: Bug #81537 [Com]: Error in regular expression using negation.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245141@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81537&edit=1

 ID:                 81537
 Comment by:         jouni dot makelainen at gmail dot com
 Reported by:        jansverre at uffe dot no
 Summary:            Error in regular expression using negation.
 Status:             Verified
 Type:               Bug
 Package:            PCRE related
 Operating System:   Ubuntu Linux 20.04
 PHP Version:        8.0.11
 Block user comment: N
 Private report:     N

 New Comment:

I have similar issue with this (simplified) regexp. I tested this with PHP docker images. It works
in 7.4-cli and 8.0-cli, but not in 8.1-cli (PCRE 10.39) or 8.2-cli (PCRE 10.40). 

Also works if negation is replaced with whitespace. 

Test script:
------------
echo preg_match('/(<\w+[^>]+href>)/', '<li><a href>');

Excepted result:
----------------
1

Actual result:
--------------
0


Previous Comments:
------------------------------------------------------------------------
[2023-01-23 08:28:00] ygwgs79hvh at gmail dot com

The problem is that in regular expressions the negation must go inside square brackets. That is not
right. Square brackets are used to match a class of characters (even when negated with a ^), which
match a single character.


<https://www.employeeconnection.one/>github.com

------------------------------------------------------------------------
[2023-01-11 06:29:22] MadeleineAshton at jourrapide dot com

Similarly, the negation variant of the character class is defined as "[^ ]" (with ^ within
the square braces), it matches a single character which is not in the specified or set of possible
characters. For example the regular expression [^abc] matches a single character except a or, b or,
c.

<https://www.myhtspace.org/>github.com

------------------------------------------------------------------------
[2022-09-21 08:24:32] antonio at softcodex dot ch

Not sure if it's the same issue.
I have this regex (see below) that doesn't work on 

PHP 7.3.33:
 7.3.33-6+ubuntu20.04.1+deb.sury.org+1 
but WILL work on the windows binary and "php:7.3-apache" docker image

PHP 8.1.10: only tested the windows binary 

preg_match( '/<(\w+)[\s\w\-]+ id="S44_i89ew">/', '<br><div
id="S44_i89ew">' , $matches );
expected result: 
array(2) { 
[0]=> string(20) "<div id="S44_i89ew">" [1]=> string(3)
"di" 
}

actial result:
array(0) { }

The strangely if you change the + quantifier after [\s\w\-] to * or ? it works.

------------------------------------------------------------------------
[2022-01-04 22:08:02] sebastiaodomingos05 at gmail dot com

As I can see, it is rather related to an extra space after adding the letter 'a'.

------------------------------------------------------------------------
[2021-12-01 15:11:36] cmb@php.net

This is apparently fixed in PCRE2 10.39 (or maybe earlier),
bundled as of PHP 8.1.1.  I'm not sure whether we should update
PHP-8.0 to this PCRE2 version.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=81537


--
Edit this bug report at https://bugs.php.net/bug.php?id=81537&edit=1


Thread (8 messages)

« previous php.bugs (#245141) next »