Req #77756 [NEW]: PCRE2 Replacement String Conditional

From: Date: Sun, 17 Mar 2019 02:02:32 +0000
Subject: Req #77756 [NEW]: PCRE2 Replacement String Conditional
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-220012@lists.php.net to get a copy of this message
From: fenniclog at gmail dot com Operating system: PHP version: 7.3.3 Package: PCRE related Bug Type: Feature/Change Request Bug description:PCRE2 Replacement String Conditional Description: ------------ When working on a chat command system for a project, I was reading up on PCRE to properly build a robust command match regex. I read up that PCRE2 supports Replacement String Conditional be using ${1:+matched:unmatched}. Ref: https://www.regular-expressions.info/replaceconditional.html#pcre2 I checked if PHP supported PCRE2 where I found a merged RFC PHP 7.3 about the topic. After testing my method, the conditional was not being parsed. Test script: --------------- <?php $message = "ban bob 24 days"; $regex = '/\{((?:(?!\d)\w)+?):?(?:(?<=\:)([[:graph:]]+))?\}/'; $commandPattern = "ban {name:\w+} {duration}"; $pattern = str_replace('/', '\/', $commandPattern); $regex = '/^'.preg_replace($regex, '(?<$1>${2:-.*})', $pattern).' ?/miu'; echo $regex.PHP_EOL; $regexMatched = (bool)preg_match($regex, $message, $matches); var_dump($regexMatched, $matches); Expected result: ---------------- /^ban (?<name>\w+) (?<duration>.*) ?/miu bool(true) array(5) { [0]=> string(15) "ban bob 24 days" ["name"]=> string(3) "bob" [1]=> string(3) "bob" ["duration"]=> string(7) "24 days" [2]=> string(7) "24 days" } Actual result: -------------- /^ban (?<name>${2:-.*}) (?<duration>${2:-.*}) ?/miu bool(false) array(0) { } -- Edit bug report at https://bugs.php.net/bug.php?id=77756&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77756&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77756&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77756&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=77756&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=77756&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=77756&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=77756&r=needscript Try newer version: https://bugs.php.net/fix.php?id=77756&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=77756&r=support Expected behavior: https://bugs.php.net/fix.php?id=77756&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=77756&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=77756&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=77756&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77756&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=77756&r=dst IIS Stability: https://bugs.php.net/fix.php?id=77756&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=77756&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=77756&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=77756&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=77756&r=mysqlcfg

« previous php.bugs (#220012) next »