PDA

View Full Version : string between two characters


skipion
11-02-2005, 11:07 AM
I need to retrieve all characters from a string within the characters ? and &.
So for example: if the string is,

http://mywebsite.adress.com/cgi-bin/testing.pl?this&is&my&test

I wanna retrieve the word 'this'. What coding could i use for this ?

FishMonger
11-02-2005, 02:53 PM
If you're talking about extracting the seperate parts of a url, you can use the URI module.
http://search.cpan.org/~gaas/URI-1.35/URI.pm

If you talking about extracting part of a general string, you can use a regex.
$str = "http://mywebsite.adress.com/cgi-bin/testing.pl?this&is&my&test";
$part = $1 if $str =~ /\?(.*?)&/;
print $part;