CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Spliting a URL with an un-usual query string

 



Danni
Novice

Apr 25, 2002, 5:09 PM

Post #1 of 2 (3983 views)
Spliting a URL with an un-usual query string Can't Post

Ive seam to have gotten a little stuck here. Im trying to reduce the code needed to split a url with strange a strange query string. Heres what im trying to do,


Code
/cmd?var=1&blah=hi+mom 
/cmd/var|1/blah|hi+mom


I need a regular expression to at least split this into


Code
cmd AND (var=1&blah=hi+mom OR var|1/blah|hi+mom)


Any clues?


Kanji
User / Moderator

May 10, 2002, 10:12 PM

Post #2 of 2 (3958 views)
Re: [Danni] Spliting a URL with an un-usual query string [In reply to] Can't Post

There are a few ways you could do this, the easiest would be to use a regular expression ...


Code
my($cmd,$rest) = $string =~ m/^\W(\w)\W(.*)$/;


However, that's very forgiving in what would work (ie, you could use :cmd:var|1/blah|hi+mom or "cmd"var?1:blah and it would still carve the string up appropriately), so you might want something a little more restrictive...


Code
my($cmd,$rest) = $string =~ m<^/([^/?]+)[/?](.*)$>;

--k.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives