Monday 15 June 2015

php - preg_match regex match more than 4 digits -



php - preg_match regex match more than 4 digits -

i have $input wich contains:

<a href="http://digitalocean.com/info/hello-23-kitty-show-1-d-zay-ya-9013294119" title="hello kitty (show &amp; zay ya" style="font-size:medium;" target="_blank" class="highlight-item">

i need preg_match lastly digits in href url (9013294119). digits can longer or shorter url's in $input varies ( allways minimum 4 charaters lenght).

i tried next regex look no luck regex experience limited:

preg_match('/^[0-9+]$/', $input, $output);

any help?

remove ^ (starts with) , $ (ends with) anchors , utilize quantifiers , lookaheads , behinds.

/(?<=-)[0-9]{4,}(?=")/

{4,} means match previous token, in case [0-9], 4 or more times.

demo

if pattern of string isn't same, can utilize href="[^"]+?([0-9]{4,})" , grouping 1 contain want.

php regex preg-match

No comments:

Post a Comment