后背疼是什么病的前兆| 爱长闭口用什么护肤品| 貂是什么动物| 拔火罐起水泡是什么原因| 什么叫强迫症| laura是什么意思| 什么动物眼睛是红色的| 血红素高是什么原因| 鼻子流黄水是什么原因| 这是什么猫| 操是什么意思| 爱理不理是什么意思| 尿频吃什么药| 糖尿病人可以吃什么| 1月11是什么星座| 睡不着吃什么药最有效| 伊维菌素是什么药| 感冒为什么会全身酸痛无力| 价值连城是什么意思| 胳膊疼痛是什么原因| 35岁属什么生肖| 胡汉三回来了什么意思| 玩是什么意思| 优生优育检查什么项目| 摩卡棕是什么颜色| 吃什么药能推迟月经| 生精补精吃什么药最快| 下眼睑红肿是什么原因| 眼睛出现飞蚊症什么原因怎么办| 阴道炎症是什么症状| 肾五行属什么| 智齿发炎吃什么药| 大肠炒什么菜好吃| 吃什么会胖| 特仑苏是什么意思| 葫芦代表什么生肖| 彩照是什么底色| pca是什么意思| 膀胱充盈欠佳什么意思| 慢性萎缩性胃炎伴糜烂吃什么药| 6月22日什么星座| 乌鸡放什么炖补气补血| 诠释的意思是什么| 先天性巨结肠有什么症状| 空气净化器什么牌子好| gas是什么意思| 腹泻拉水是什么原因| 夏天吃什么最好| 2005属什么生肖| 食指有痣代表什么意思| 尿等待是什么原因| 什么体质不易怀孕| 大作是什么意思| 吃完香蕉不能吃什么| 幽门螺杆菌感染吃什么药| 断子绝孙是什么意思| 菠菜和豆腐为什么不能一起吃| 为非作歹是什么意思| 3.7号是什么星座| 蝙蝠侠叫什么| 什么茶能去体内湿气| 为什么叫马路| 口苦吃什么中药| 古今内衣是什么档次| 五月十六是什么星座| 鳄鱼是什么动物| 心率快吃什么药效果更佳| 减肥期间早餐应该吃什么| 右下眼皮跳是什么预兆| 滑丝是什么意思| 什么得当| 结节是什么意思| 感冒吃什么消炎药| 为什么腿会酸痛| 里急后重是什么意思| 石斛长什么样子图片| 茶油有什么功效| 挚友什么意思| 石斛长什么样子图片| 气血两虚吃什么药| 代谢慢吃什么效果最快| ep是什么| 腰酸痛挂什么科| kappa是什么牌子| 老汉推车是什么意思| 夏枯草治什么病| 孤帆远影碧空尽的尽是什么意思| 显现是什么意思| 腰肌劳损用什么药| 吐槽什么意思| 北京有什么| 颖五行属什么| 用醋泡脚有什么好处| 子宫偏小是什么原因| 狮子座是什么性格| 伏笔是什么意思| 曹操是个什么样的人| 民航是什么意思| 草木灰是什么| 金匮肾气丸主治什么病| 养狗养不活是什么兆头| 假冒警察什么罪怎么判| 老过敏是缺什么维生素| 男人说冷静一段时间是什么意思| 秋天的落叶像什么| 毛泽东是什么样的人| 庚辰五行属什么| exo是什么意思| 榴莲壳有什么作用| 手突然抖动是什么原因| 枫树的叶子像什么| 糖原是什么| 细菌性肠炎吃什么药| 慰藉是什么意思| 洗内裤用什么洗比较好| 胳膊疼是什么原因| 为什么全身酸痛| 羽丝绒是什么材料| 多吃西瓜有什么好处| 西洋参跟花旗参有什么区别| 80岁是什么之年| 倒拔垂杨柳是什么意思| 红豆薏仁水有什么功效| 什么叫牙齿根管治疗| 牙疼是什么病的前兆| 牙科属于什么科| 早孕试纸什么时候测最准确| 棺材一般用什么木头| 斗拱是什么意思| 乳腺增生吃什么药最好| rts是什么意思| 胎儿左心室灶状强回声是什么意思| con是什么| cps是什么单位| 下腹坠胀是什么原因| 深是什么生肖| 就绪是什么意思| 君子兰有什么特点| 晚上睡觉手麻木是什么原因| 吃什么可以提高免疫力和抵抗力| 碳酸氢铵是什么东西| 湿热体质吃什么食物好| 脚气吃什么维生素| 缺锌有什么症状| pop是什么| 老人越来越瘦是什么原因| 大校相当于政府什么官| 斑点狗是什么品种| 惊恐是什么意思| 二院是什么医院| 6月份能种什么菜| 为什么不开朱元璋的墓| 今年什么时候进入伏天| 奴才是什么意思| 小姨是什么关系| 脾肾气虚的症状是什么| 不惑之年什么意思| 长寿花什么时候开花| 走路气喘是什么原因| 吃什么补气血效果最好| 柳仙是什么仙| 猫咪不能吃什么| 什么叫近视| 剪头发叫什么手术| 1964年什么命| 什么是乐高| 脚底有痣代表什么意思| 中元节注意什么| 兰花代表什么象征意义| 禅意是什么意思| 仙鹤代表什么生肖| 乌梅有什么功效| 1948年属什么| 智能手环什么品牌好| 脚痒脱皮是什么原因| 姨妈是什么意思| 早上起床腰疼是什么原因| 高血压适合喝什么茶| 红参和高丽参有什么区别| 自制力是什么意思| 为什么心里老是想着死| 蚊香是什么做的| 9月10日是什么日子| 血晕症是什么病| 什么是花青素| 小孩晚上睡觉流口水是什么原因| 冒泡是什么意思| 垂体催乳素高是什么原因| 弓形虫抗体阳性是什么意思| 次抛是什么意思| 十月二十八是什么星座| 狗是什么生肖| 铁观音是什么茶类| 挺拔的意思是什么| 苹能组什么词| 格桑花的花语是什么| 御史相当于现在什么官| 做水果捞用什么酸奶好| 肛门痒痒的是什么原因| 办理暂住证需要什么材料| 藕粉色是什么颜色| 看乳腺结节挂什么科| 手指甲有月牙代表什么| vd是什么| 升白针叫什么名字| 处女座男和什么星座最配| 洋姜有什么功效与作用| 什么人不能吃榴莲| 性冷淡是什么| 留低是什么意思| 阴瑜伽是什么意思| 护理员是干什么的| 什么是总胆固醇| 半熟芝士是什么意思| 肝内脂肪浸润是什么意思| 更年期挂什么科| 性冷淡吃什么药| skirt什么意思| 血压高不能吃什么| 口语化是什么意思| oder是什么意思| hcho是什么意思| 圆寂为什么坐着就死了| 占有欲强是什么意思| 砚台是什么| 什么叫结节| 五月二十二是什么星座| 为什么老是想吐| 章鱼的血是什么颜色| 生孩子送什么花比较好| 肚子胀气放屁吃什么药| 无以言表是什么意思| 衔接是什么意思| 蛇床子是什么| 口臭看什么科| 早上6点到7点是什么时辰| 早上的太阳叫什么| 抵税是什么意思| 夫妻肺片里面都有什么| 助听器什么牌子好| 什么水果去火效果最好| 放化疗期间吃什么好| 为什么蚊子要吸血| 压抑什么意思| 为什么长智齿| 狐臭是什么原因| 非洲讲什么语言| 欧尼酱什么意思| 90岁属什么生肖| 5月20号是什么星座| 好学不倦什么意思| 尿泡沫多是什么原因| 女生生日送什么礼物好| 手不什么| 骨龄大于年龄意味着什么| 胆囊炎挂什么科室| spf50是什么意思| 阴道里面痒用什么药| 上睑下垂是什么原因造成的| 5月25日是什么星座| 七月生日是什么星座| 梦见自己假牙掉了是什么意思| o型血和a型血生的孩子是什么血型| 生酮饮食是什么| 百度
php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #71959 preg_match_all: flag/retval to require or determine string fully consumed
Submitted: 2025-08-06 20:07 UTC Modified: 2025-08-06 16:38 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: stilezy at gmail dot com Assigned:
Status: Open Package: PCRE related
PHP Version: 5.6.20 OS:
Private report: No CVE-ID: None
 [2025-08-06 20:07 UTC] stilezy at gmail dot com
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.



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2025-08-06 16:38 UTC] nikic@php.net
Some pointers:

A more efficient way to check whether everything was matched is to add up the lengths of the matches and check whether its equal to the string length.

Additionally the \G anchor can be used to avoid continuing matching if the matches aren't directly adjacent. So something like this:

$subject = '993A27C5502A7Q3B';
preg_match_all("/\G\d+[A-C]/", $subject, $matches);
var_dump($matches);

Will yield:

array(1) {
  [0]=>
  array(3) {
    [0]=>
    string(4) "993A"
    [1]=>
    string(3) "27C"
    [2]=>
    string(5) "5502A"
  }
}

This gives you the matches until the first failure (at 7Q) and does not proceed past it.

Overall I don't think it's worthwhile to add such a flag. Yes, it would simplify the specific use-case where you're only interested in whether the entire string is consumed. However it would not cover small variations, like also wanting to print an error that includes the offset at which the match failed. You can easily do that with \G and PREG_OFFSET_CAPTURE, but a PREG_CONSUME_ALL flag would not help you.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Aug 06 06:00:02 2025 UTC
安娜苏香水什么档次 羊膜束带是什么意思 汧是什么意思 脑死亡是什么意思 白蛋白高是什么原因
tfcc是什么 伏特加是什么酒 老年人腿疼是什么原因引起的 省委组织部长是什么级别 龟头感染用什么药
流黄鼻涕是什么原因 mrmrs是什么牌子 农历5月17日是什么星座 母乳什么味道 婴儿补铁吃什么铁剂
尿酸高是什么问题 血小板压积偏高是什么意思 单绒双羊是什么意思 玉米排骨汤放什么调料 什么风大雨
老年人嘴唇发紫是什么原因hcv8jop7ns2r.cn 帕金森吃什么药效果好hcv9jop1ns1r.cn 小孩头发黄是什么原因hcv7jop9ns9r.cn 后羿射日什么意思520myf.com 什么是过敏hcv9jop0ns5r.cn
男生生日礼物送什么hcv9jop2ns2r.cn 孕妇头疼是什么原因hcv8jop3ns5r.cn 九重天是什么意思hcv7jop6ns3r.cn 吃虾不能和什么一起吃hcv9jop3ns5r.cn 什么目寸光成语wuhaiwuya.com
阴阳人是什么意思hcv9jop5ns3r.cn 什么是绿茶女hcv9jop2ns6r.cn 11月20号什么星座hcv8jop4ns6r.cn 梦遗是什么onlinewuye.com 肺部感染吃什么药clwhiglsz.com
双红出彩是什么生肖hcv8jop0ns8r.cn 眼睛浮肿是什么原因引起的hcv8jop8ns2r.cn 为什么回族不吃猪肉hcv9jop0ns7r.cn 筛是什么意思inbungee.com 吃什么瘦肚子脂肪最快hcv8jop5ns6r.cn
百度