regex - Return first substring till It Matches in PHP -
i stuck this
i have string let say
$name = 'asdf_aadf01_2*f854?# sadf'; and need
'asdf_aadf01_2' in return means alpha numeric underscore until non alphanumeric , _ character found
use:
preg_match('/\w*/', $name, $match); $match[0] contain you're looking for.
\w matches alphanumeric or underscore character. * quantifier means match 0 or more of preceding element.
Comments
Post a Comment