Avatar of Vlearns
Vlearns asked on

perl question

Hi

I have the following perl code that extracts   Alexander_Hamilton_Jr. from the following string

http://en.wiedia.org/wiki/Alexander_Hamilton_Jr./Sr._High_School

it is supposed to give Alexander_Hamilton_Jr./Sr._High_School


 ($part0,$id,$wikiid,$fiwd,$part4)=m{(.*?(?:(www\.idb\.com)|(en\.wiedia\.org)|(frase\.com))/[^/]*)/([^/]*)};

what do i need to do
Perl

Avatar of undefined
Last Comment
Vlearns

8/22/2022 - Mon
farzanj

Try this:

my $str = "http://en.wiedia.org/wiki/Alexander_Hamilton_Jr./Sr._High_School";

my ($match) = $str =~ m{wiki/(.+)};

print $match;

Open in new window

ASKER
Vlearns

hi

thanks for the reply
can you help by changing the existing code, as you can see it matches other domains as well

thanks
farzanj

Ok, changed it like this and it works:

$_ = $str;

my ($id,$wikiid,$fiwd) = m{(.*?(www\.idb\.com|en\.wiedia\.org|frase\.com)(?:/wiki)/[^/]*)/([^/]*)};

print "$wikiid/$fiwd";

Open in new window


Your expression missed the wiki part altogether.  Also you don't need to put your URLs in brackets.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
wilcoxon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Vlearns

thank you very much