in reply to url get variables regex

Do it with URI and URI::QueryParam and you'll have code that works much more reliably and is easier to read and extend. Here's a snippet to get you going-

use URI; use URI::QueryParam; while ( <DATA> ) { chomp; my $uri = URI->new($_); next unless $uri->scheme eq 'http'; next unless $uri->query_param; print $uri, $/; for my $param ( $uri->query_param ) { printf(" %s --> %s\n", $param, join(", ", $uri->query_param($param)) ); } } __DATA__ http://google.com/?var1=aaaa&var2=aa https://google.com/?var1=aaaa&var2=aa http://google.com/ ftp://google.com/ mailto:moo@gmail.com http://google.com/?var=one&var=two&var=three

Replies are listed 'Best First'.
Re^2: url get variables regex
by clone4 (Sexton) on May 13, 2009 at 23:52 UTC
    Thanks for the snippet, I will definitely have a look at that!