preg_replace - help with regular expression
Posted: Mon Feb 12, 2007 12:02 pm
Hey guys,
I need help with a regular expression to replace a string passed to preg_replace, with the value in square brackets contained in the string.
E.g.
original string: 'foo = [bar]'
required string: 'bar'
Initially I can do:
$string = 'foo=[bar]';
echo preg_replace('%foo=(.*)%si', '\1', $string);
output:
[bar]
I've tried various expressions to ignore the square brackets, but nothings worked, so here I am!
Any ideas?
Thanks in advance.
I need help with a regular expression to replace a string passed to preg_replace, with the value in square brackets contained in the string.
E.g.
original string: 'foo = [bar]'
required string: 'bar'
Initially I can do:
$string = 'foo=[bar]';
echo preg_replace('%foo=(.*)%si', '\1', $string);
output:
[bar]
I've tried various expressions to ignore the square brackets, but nothings worked, so here I am!
Any ideas?
Thanks in advance.