regex - Match a domain in a urls ending with specified word -
i have list of urls need sort. try explain need.
example:
http://test56.testdom.com/dev123/85056704/test/test.php?something=else&t=1 http://test14.testdoma.tv/dev234/93181034/test/backup.zip http://test22.testdomai.me/dev945/23145034/test/test.zip http://test12.testdomain.co.uk/dev184/95342034/test/random?random=123&stuff=true http://test76.testdomains.de/dev643/13453534/test/random.zip
i need regex match full domain name, in urls ending zip
, this:
test14.testdoma.tv test22.testdomai.me test76.testdomains.de
so basically: "if there's zip
, match test
/
".
how can write regex this?
in notepad++, don't output you'd in programming language. can use find , replace regex, i.e.:
find: https?://(.*?)/.*\.zip
replace: $1
the above, replace url's ending in zip, corresponding domain.
subject:
http://test56.testdom.com/dev123/85056704/test/test.php?something=else&t=1 http://test14.testdoma.tv/dev234/93181034/test/backup.zip http://test22.testdomai.me/dev945/23145034/test/test.zip http://test12.testdomain.co.uk/dev184/95342034/test/random?random=123&stuff=true http://test76.testdomains.de/dev643/13453534/test/random.zip
output:
http://test56.testdom.com/dev123/85056704/test/test.php?something=else&t=1 test14.testdoma.tv test22.testdomai.me http://test12.testdomain.co.uk/dev184/95342034/test/random?random=123&stuff=true test76.testdomains.de
update:
with javascript can use regex:
var myregexp = /https?:\/\/(.*?)\/.*\.zip/img;
and php:
$urls = <<< eof http://test56.testdom.com/dev123/85056704/test/test.php?something=else&t=1 http://test14.testdoma.tv/dev234/93181034/test/backup.zip http://test22.testdomai.me/dev945/23145034/test/test.zip http://test12.testdomain.co.uk/dev184/95342034/test/random?random=123&stuff=true http://test76.testdomains.de/dev643/13453534/test/random.zip eof; preg_match_all('%https?://(.*?)/.*\.zip%im', $urls, $matches, preg_pattern_order); ($i = 0; $i < count($matches[1]); $i++) { echo $matches[1][$i]; }
Comments
Post a Comment