Bug #71036 [Ver]: When using /x modifier, a "/" in a regex comment is seen as a regex delimiter

From: Date: Fri, 17 Jun 2016 14:53:57 +0000
Subject: Bug #71036 [Ver]: When using /x modifier, a "/" in a regex comment is seen as a regex delimiter
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201696@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71036&edit=1

 ID:                 71036
 Updated by:         cmb@php.net
 Reported by:        cmanley at xs4all dot nl
 Summary:            When using /x modifier, a "/" in a regex comment is
                     seen as a regex delimiter
 Status:             Verified
 Type:               Bug
 Package:            PCRE related
 Operating System:   Debian 8.2
 PHP Version:        5.6.14-0+deb8u1
 Block user comment: N
 Private report:     N

 New Comment:

For reference: <https://3v4l.org/jh4EJ>.

There's obviously no provision for PCRE_EXTENDED comments in
place[1]. To cater to that, the ending delimiter would have to be
searched from the end of the regex string to be able to get the
modifiers first, and after that a second run would be required to
check that the delimiter is not used anywhere else in the regex
where it is not allowed.

Not sure if it's worth the trouble; maybe we should just change
the documentation accordingly?

[1] <https://github.com/php/php-src/blob/php-7.0.7/ext/pcre/php_pcre.c#L351-L391>


Previous Comments:
------------------------------------------------------------------------
[2015-12-05 01:28:57] cmanley at xs4all dot nl

.

------------------------------------------------------------------------
[2015-12-05 01:26:32] cmanley at xs4all dot nl

Description:
------------
The documentation for the x (PCRE_EXTENDED) modifier states:
"characters between an unescaped # outside a character class and the next newline character,
inclusive, are also ignored"

Yet this is not the case in my test example:
The "/" in the regex comment "# firstname/alias" is seen as a regex delimiter.

Test script:
---------------
<?php
$fullname = 'Joe Blow';
if (preg_match('/^
	(\S+)	# firstname/alias
	\s+
	\S+	# surname
$/x', $fullname, $matches)) {
	print $matches[1] . "\n";
}


Expected result:
----------------
Joe

Actual result:
--------------
PHP Warning:  preg_match(): Unknown modifier 'a' in /home/cmanley/t.php on line 8


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



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


Thread (4 messages)

« previous php.bugs (#201696) next »