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

Popular posts from this blog

html - jquery - p element wont show after I hid it -

python - BeautifulSoup: How to get the nearest tag -

mysql - Trying to get RmySQL to work but not understanding bash's export or filesystem conventions -