我想在字符串的“%”中找到所有子字符串,但是我不明白为什么它只能找到“ id”.
$test = '';
$token_regex_inside_tags = "/]*%([\w]+)%[^>]*)>/";
preg_match_all($token_regex_inside_tags, $test, $matches);
解决方法:
假设:-我假设只有在%介于<>之间时,才需要查找%内的内容.
您可以使用此正则表达式使用\G
(?:\G(?!\A)|]*%([^%>]*)%
正则表达式分解
(?:
\G(?!\A) #End of previous match
| #Alternation
< #Match < literally
)
[^%>]* #Find anything that's not % or >
%([^%>]*)% #Find the content within %
在您的正则表达式中
< #Matches < literally
(
[^>]* #Moves till > is found. Here its in end
%([\w]+)% #This part backtracks from last but is just able to find only the last content within two %
[^>]*
)>
标签:php,regex
来源: https://codeday.me/bug/20191026/1939473.html