PHP正则表达式:从<;a>;幸运<;b>;魅力</b></a>;
请求问题: 摘词PHP正则表达式:从<;a>;幸运<;b>;魅力</b></a>;,php,expression,Php,Expression,请求问题: 摘词 lucky charms 从字符串: <a>lucky <b>charms</b></a> 幸运符 我的尝试: preg_match_all("/<(.*)>(.*)<\/(.*)>+/is", $text, $matches); print_r($matches); preg_match_all(“/(.*)+/is”,$text,$matches); 打印(匹配项); 结果: Array (
lucky
charms
从字符串:
<a>lucky <b>charms</b></a>
幸运符
我的尝试:
preg_match_all("/<(.*)>(.*)<\/(.*)>+/is", $text, $matches);
print_r($matches);
preg_match_all(“/(.*)+/is”,$text,$matches);
打印(匹配项);
结果:
Array
(
[0] => Array
(
[0] => <a>lucky <b>charms</b></a>
)
[1] => Array
(
[0] => a>lucky <b>charms</b
)
[2] => Array
(
[0] =>
)
[3] => Array
(
[0] => a
)
)
数组
(
[0]=>阵列
(
[0]=>幸运符
)
[1] =>阵列
(
[0]=>a>幸运符数组
(
[0] =>
)
[3] =>阵列
(
[0]=>a
)
)
如果您始终具有该结构,则可以使用:
preg_match("#<(.*?)>(.*?)<(.*?)>(.*?)</\\3></\\1>#is", '<a>lucky <b>charms</b></a>', $matches);
你的正则表达式是不合适的,因为*gready是用来做*非gready的还是用这样的方式改变你的正则表达式
<([^>]+)>(.*?)</\1>
]+)>(*
在结束标记和下一个开始标记之间的所有内容如何
preg_match_all("/\>([^\<]+)\</is", $text, $matches);
有什么问题吗?Regex太贪婪了?减少贪心。可能重复您是否尝试过使用
strip_tags()
?@Mathieu Imbert我不想剥去标签。因为我以后会更换幸运符和护身符。。还需要标签你可以复制一份,然后在副本上使用条形标签。然后你会得到你的幸运符,但不会失去你原来的标签
preg_match_all("/\>([^\<]+)\</is", $text, $matches);
Array
(
[0] => Array
(
[0] => >lucky <
[1] => >charms<
)
[1] => Array
(
[0] => lucky
[1] => charms
)
)