
May 8th, 2012, 01:15 AM
|
|
|
Please try:
Code:
(?<=(\[)|(\{)).+?(?=(?(1)\]|\}))
Lookahead and lookbehind is used to cut the word inside brackets, not including the brackets themselves. ?(1) condition checks what kind of opening bracket have you used, { or [, and matches the appropriate closing bracket. The non-greedy repetition .+? avoids eating everything until the last bracket in the text; only the text inside one bracket is consumed.
Code:
<?php
$a = '{silverado} [silverado]';
$a = preg_replace( '/(?<=(\[)|(\{)).+?(?=(?(1)\]|\}))/', '', $a );
echo $a;
?>
|