By now i'm using regex: '/{(.*?)}/'
to get everything inside curly barackets in strings like: 'abc {get me} def {and get me}'
which works fine.
Now i'm looking for a way to exclude brackets, which are surrounded by brackets themselves. The string should be self-explanatory: 'abc {get me {!but not me!}} def {and get {!but not me again!} me} ghi'
.
The following code should illustrate my needs...
<?php
$regex = '/{(.*?)}/';
$string = 'abc {get me {!but not me!}} def {and get {!but not me again!} me} ghi';
preg_match_all( $regex, $string, $matches );
print_r( $matches[1] );
?>
prints:
Array
(
[0] => get me {!but not me!
[1] => and get {!but not me again!
)
but should be:
Array
(
[0] => get me {!but not me!}
[1] => and get {!but not me again!} me
)
Until now i was not able to find a solution via Google and looking forward to get one at SO.
regards
EDIT: Actually a very similar question was asked and answered on SO. But if you are not familiar with regex it's really hard to change from wrapper (...) to {...}. So you can not simply take the one pattern given by the answer (see link above) and search-replace all '(' & ')' with '{' & '}'. You really have to understand what's going on there.
But if you understand this pattern enough to customize it you probably would be able to write it on your own...