Goodday,
I have this script beneath to recognize the first tag ([Test1])
But all it does with the uri I have right now is take the first bracket and the last one,
so the output is “Test1] Title [Test9”
I want the output to be “Test1“. I already tried to change the preg_match, but it seems I’m not getting what I want.
Hope someone can help me to get on the right path.
<?php
$uri = "[Test1] Title [Test9].jpg";
$str = "'".$uri."'";
if (preg_match('/\[([^\)]+)\]/', $str, $matches)) {
echo "[".$matches[1]."]";
}
?>
Thanks in advance.
You have to use ‘?’ sign in order to get the ungreedy matches:
test it online