[英]How to find this regex using PHP
在字符串中找到所有<1></1> and <2></2> and <3></3>...
<(\d+)></\1>
should work. 应该管用。 This ensures that the regex won't match
<1></4>
for example. 这样可以确保正则表达式与例如
<1></4>
不匹配。
\\1
is here a backreference which must match exactly the same string as the first capturing group (the (\\d+)
in the first angle brackets). \\1
是一个反向引用 ,必须与第一个捕获组(第一个尖括号中的(\\d+)
完全相同。
One regex to match any of them? 一个正则表达式可以匹配其中任何一个?
<([1-3])></\1>
Should there code allow for anything to be posted in between the >
and the <
? 是否应该有代码允许在
>
和<
之间发布任何内容? Something like this then: 然后是这样的:
<([1-3])>(.*?)</\1>
You can use the following regex: <[0-9]></[0-9]>
您可以使用以下正则表达式:
<[0-9]></[0-9]>
EDIT: To avoid that the search matches <2></3>
too, you can use a sub-expression and a backreference to instantiate it: <([0-9])></\\1>
编辑:为避免搜索也匹配
<2></3>
,可以使用子表达式和后向引用实例化它: <([0-9])></\\1>
<STYLE[^>]*>([\s\S]*?)<\/STYLE[^>]*>
Just replace STYLE with your tag like 1, 2 whatever.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.