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

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -