php - PHP regex backreference not matching properly
问题描述
The following code is working as intended:
<?php
preg_match_all('|<[^>]+>.*</[^>]+>|U',
"<b>example: </b><div align=left>this is a test</div>",
$out);
echo $out[0][0] . ", " . $out[0][1] . "\n";
?>
It matches the first b tag and then moves on to match the div tag as it should. However, when I use a backreference only the b tag is matched.
<?php
preg_match_all('|<([^>]+)>.*</\1>|U',
"<b>example: </b><div align=left>this is a test</div>",
$out);
echo $out[0][0] . ", " . $out[0][1] . "\n";
?>
What is incorrect here?
This question has been marked as duplicate. I read the post but was not convinced it actually was a duplicate question. However, the posted comment was helpful and made me understand my error. Thanks.
解决方案
推荐阅读
- php - 我该如何解决这个未定义的索引:?
- c - GCC不同的实际内存分配量然后我分配给程序中的变量
- google-apps-script - 获取活动行并设置列
- objective-c - MessageComposeResult UIAlert 未显示
- tensorflow - tensorflow_lite Prelu 不支持 dims->size = 2
- ios - 动画 tableview 高度约束,但动画正在跳跃
- mysql - 拥有多个地址表是个好主意吗?
- java - 在 liferay 中使用 commons-fileupload 无法正确解析请求
- node.js - 为什么将 WSDL 文件传递给肥皂服务器?
- sql - 在 Oracle SQL 中使用另一个表中的数据创建一个新表