Link to home
Start Free TrialLog in
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
Avatar of farzanj
farzanj
Flag of Canada image

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

Avatar of Vlearns
Vlearns

ASKER

hi

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

thanks
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.
ASKER CERTIFIED SOLUTION
Avatar of wilcoxon
wilcoxon
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vlearns

ASKER

thank you very much