Req #71959 [NEW]: preg_match_all: flag/retval to require or determine string fully consumed

From: Date: Mon, 04 Apr 2016 20:07:07 +0000
Subject: Req #71959 [NEW]: preg_match_all: flag/retval to require or determine string fully consumed
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200350@lists.php.net to get a copy of this message
From: stilezy at gmail dot com Operating system: PHP version: 5.6.20 Package: PCRE related Bug Type: Feature/Change Request Bug description:preg_match_all: flag/retval to require or determine string fully consumed Description: ------------ Scenario: An input or subject string is expected to be of the form /^(SOME_REGEX)+$/ If it matches then the substrings will be extracted using preg_match_all() Example: $subject = '993A27C5502A3B'; and is expected to match $pattern = '/^(\d+[A-C])+$/ '; (obviously here it does) If it matches $pattern then the matches are extracted: preg_match_all("/(\d+[A-C])/", $subject, $matches); The weakness is that there isn't a way to stipulate or test whether preg_match_all() has consumed the entire subject string. So we have to first test with one preg_match() whether or not $subject matches a repetition of $pattern, then a second preg_match_all() to extract the matches (i.e. break down $subject) if it does. This must be a very common scenario for preg_match_all, as a person matching all substrings may want to confirm whether the whole string is used. REQUEST: Can there be a flag added such as PREG_CONSUME_ALL that requires preg_match_all() to have consumed the entire string, and if it did not, returns FALSE, so that this double regex use isn't needed? Also perhaps a PREG_CONSUMED_ALL flag that causes the return value to indicate TRUE or FALSE depending whether or not the subject was fully consumed. I think this would be useful. NOTES - 1) By "consumed" I mean that the matches, imploded, make up the original string, ie natural meaning. 2) Perhaps the same or similar enhancement might benefit preg_split() as well, and any other preg_*() functions that attempt to "walk" the subject and repeatedly act as often as possible upon it. -- Edit bug report at https://bugs.php.net/bug.php?id=71959&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71959&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71959&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71959&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=71959&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=71959&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=71959&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=71959&r=needscript Try newer version: https://bugs.php.net/fix.php?id=71959&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=71959&r=support Expected behavior: https://bugs.php.net/fix.php?id=71959&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=71959&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=71959&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=71959&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71959&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=71959&r=dst IIS Stability: https://bugs.php.net/fix.php?id=71959&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=71959&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=71959&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=71959&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=71959&r=mysqlcfg

« previous php.bugs (#200350) next »