Reputation:
I have a string in PHP for example $string = "Blabla [word]";
I would like to filter the word between the '[' brackets.
The result should be like this $substring = "word";
thanks
Upvotes: 1
Views: 1457
Reputation: 2406
Try:
preg_match ('/\[(.*)\]$/', $string, $matches);
$substring = $matches[1];
var_dump ($substring);
Upvotes: 1
Reputation: 319561
preg_match('/\[(.*?)\]/', $string, $match);
$substring = $match[1];
Upvotes: 3