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
preg_match('/\[(.*?)\]/', $string, $match);
$substring = $match[1];
preg_match_all() with 'U' modifier (PCRE_UNGREEDY) instead of preg_match(). I can't get though, why do ".*?" and ".*" return different results with strings like "foo [bar] something [else]".*? is a lazy quantifier, the same what 'U' flag does: Matches pattern of any length but prefers the shortest one.?, tx for explanation