Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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

Replies are listed 'Best First'.
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 Anonymous Monk on Jan 11, 2013 at 09:25 UTC
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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2017-11-21 03:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (295 votes). Check out past polls.

    Notices?