Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

match the urls

by Anonymous Monk
on Jan 11, 2013 at 09:21 UTC ( #1012836=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Please help in writing the regex. match the url below
https://www.abc.com/ap/ap/top-news/76/nTk3M/ https://www.abc.com/videos/news/eye-catching/vmxJr https://www.abc.com/ap/top/45/state-political-news/fgdfgd
and not match
https://www.abc.com/ap/ap/top-news/ https://www.abc.com/
There should be some value after three "/"'s after the domain name and should match

Comment on match the urls
Select or Download Code
Re: match the urls
by Anonymous Monk on Jan 11, 2013 at 09:25 UTC
Re: match the urls
by tobyink (Abbot) on Jan 11, 2013 at 09:38 UTC
    use 5.010; use strict; use warnings; my @urls = qw< https://www.abc.com/ap/ap/top-news/76/nTk3M/ https://www.abc.com/videos/news/eye-catching/vmxJr https://www.abc.com/ap/top/45/state-political-news/fgdfgd https://www.abc.com/ap/ap/top-news/ https://www.abc.com/ >; for (@urls) { m{ ^ https://www\.abc\.com/ # correct stem (?: .+? / ){3} # non-greedy string then slash x 3 .+ # at least one other character }x ? say("MATCH: $_") : say("NOT: $_") }
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re: match the urls
by sen (Hermit) on Jan 11, 2013 at 14:35 UTC
    #!/usr/bin/perl use strict; use warnings; my @array = ('https://www.abc.com/ap/ap/top-news/76/nTk3M/','https://w +ww.abc.com/videos/news/eye-catching/vmxJr','https://www.abc.com/ap/to +p/45/state-politic al-news/fgdfgd', 'https://www.abc.com/ap/ap/top-news/', 'https://www.a +bc.com/'); my @b = grep {$_ =~ /\w+\:\/\/\w+\.\w+\.\w+\/(\w+\-?\w+?\/){3,}./ } @a +rray; print "@b";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1012836]
Approved by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (15)
As of 2015-07-02 13:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (40 votes), past polls