regex - PHP - regular expression (preg_match) -


<?php $string = "http://example.com/file/d1 http://example.com/file/d2 http://example.com/file/d3"; preg_match_all('/(https?\:\/\/)?(www\.)?example\.com\/file\/(\w+)/i', $string, $matches);   foreach($matches[3] $value) {   print $value;   } ?> 

i want preg match third link , "d3".
dont want matches other 2 links. why should check if link has whitespace @ beginning or end.
know match whitespace expression \s. tried somehow don't it. :(

you can add $ match end of string this, , return last one.

preg_match_all('/(https?\:\/\/)?(www\.)?example\.com\/file\/(\w+)$/i', $string, $matches);   

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -