开发者

regex (preg_match_all)

开发者 https://www.devze.com 2023-04-07 15:55 出处:网络
I can match this string {string} by using this regex : /{(.*)}/s in PHP\'s preg_replace_callback function.

I can match this string {string} by using this regex : /{(.*)}/s in PHP's preg_replace_callback function.

But I don't what to match that string if that string is contained between tags like {tag}{/t开发者_开发问答ag},

For example :

I don't want to match {string} in {tag} Anything Here {string} Anything Here {/tag}.

Any suggestions (or maybe examples) are most welcome.


You can play with that :

preg_match_all("/(\{string\})|(\{tag\}.+\{.+tag\})/", $str, $m);

echo "<pre>";
print_r($m);
echo "</pre>";

As you will see, that expression will return a m with three array elements. The second array ellement contain all the {string} that are not into {tag}....{string}....{/tag}

0

精彩评论

暂无评论...
验证码 换一张
取 消