<?php
$str = <<<TXT
/something/ and /something?foo=bar
are ok, but /another/something/ is not.
Ah, /something is ok without trailing
slash is ok as well.
TXT;
$r = '~(?:\s|^)(/something/?(?:\?[^\s]+)?)~';
preg_match_all($r, $str, $m);
print_r($m[1]);