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.
preg_replace - help with regular expression
Moderator: General Moderators
your question is very confusing... try and be more clear when asking questions. I can't understand what you're asking. Hope this helps:
viewtopic.php?p=357139
viewtopic.php?p=357139
-
blackbeard
- Forum Contributor
- Posts: 123
- Joined: Thu Aug 03, 2006 6:20 pm
Re: preg_replace - help with regular expression
I think this will work:
Code: Select all
$string = 'foo=[bar]';
echo preg_replace('%foo=\[(.*)\]%si', '\1', $string);