正则表达式重复星号模式匹配

问题描述 投票:0回答:1

如果我做正则表达式匹配

preg_match('/^[*]{2}((?:[^*]|[*][^*]*[*])+?)[*]{2}(?![*]{2})/s', "**A** **B**", $matches);

我得到了我想要的$matches的结果

Array ( [0] => **A** [1] => A )

但我不知道如何修改正则表达式以在输入文本中产生$matches中相同的结果而没有中间的空格,即"**A****B**"

php regex preg-match
1个回答
1
投票

它看起来像正则表达式匹配

preg_match('/^[*]{2}((?:[^*]|[*][^*]*[*])+?)[*]{2}/s', "**A****B**", $matches);

得到我想要的$matches的结果

Array ( [0] => **A** [1] => A )
© www.soinside.com 2019 - 2024. All rights reserved.