Reputation: 2052
I need PHP pcre regex to find content of all curly brackets... Why is this regex doesn't work?
<?php
$str = "test{it}test{/it}test";
$ret = preg_match_all("#\{.?\}#u", $str, $matches);
print_r($matches);
?>
I expect $matches
to contain {it}
and {/it}
- but it's empty....
Upvotes: 1
Views: 180
Reputation: 4887
What your regex does:
\{.?\}
What you want from your regex:
\{.*?\}
Upvotes: 3
Reputation: 20014
I think this is the version you are looking for: {.*?}
with the *
before the ?
$re = "/{.*?}/";
$str = "test{it}test{/it}test";
preg_match_all($re, $str, $matches);
Upvotes: 1