The code you found on the internet is kind of irrelevant. In order to achieve what you want you need something like this:
$str = "[image name=ubuntustudio-tribal-54] "; $pat = "~\[image name=([^\]]+)~i"; preg_match($pat, $str, $matches); $name = $matches;
$name would be bound to
See the docs for more details regarding PHP’s preg_match.
See also, this great source of info about Regular Expressions in general.