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
VlearnsAsked:
Who is Participating?
 
wilcoxonCommented:
The simplest change necessary would be to just change the very last portion of the regex:
 ($part0,$id,$wikiid,$fiwd,$part4)=m{(.*?(?:(www\.idb\.com)|(en\.wiedia\.org)|(frase\.com))/[^/]*)/(.*)};

Open in new window

Now it will match anything after the "wiki" (or similar) portion of the URL.  Some examples:
http://en.wiedia.org/wiki/Alexander_Hamilton_Jr./Sr._High_School -> Alexander_Hamilton_Jr./Sr._High_School
http://en.wiedia.org/whatever/this/is/long/url.html -> this/is/long/url.html
0
 
farzanjCommented:
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

0
 
VlearnsAuthor Commented:
hi

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

thanks
0
 
farzanjCommented:
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.
0
 
VlearnsAuthor Commented:
thank you very much
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.