parseUri: Split URLs in ColdFusion
Update: I've added a JavaScript implementation of the following UDF. See parseUri: Split URLs in JavaScript.
Here's a UDF I wrote recently which allows me to show off my regex skillz. parseUri() splits any well-formed URI into its components (all are optional).
The core code is already very brief, but I could replace everything within the <cfloop> with one line of code if I didn't have to account for bugs in the reFind() function (tested in CF7). Note that all components are split with a single regex, using backreferences. My favorite part of this UDF is its robust support for splitting the directory path and filename (it supports directories with periods, and without a trailing backslash), which I haven't seen matched in other URI parsers.
Since the function returns a struct, you can do, e.g., parseUri(uri).anchor, etc. Check it out:


Comment by hua on 24 August 2007:
very cool! thanks for sharing this.
one scope issue: line 35 “Variables.uriParts.pos” should be “uriParts.pos”
Comment by Stacey on 17 November 2009:
Found the same issue as hua… one suggestion, could you split the host part into subdomain and domain too?
Comment by Paolo on 29 July 2010:
Simple, robust and powerful UDF! Exactly what I looking for!
Great work!
Comment by Joshua Gonzalez on 26 May 2011:
Thanks man!
Comment by Vjozryic on 3 September 2011:
Thanks funny site incest art toplisty atdn
Comment by Auogtbkj on 8 September 2011:
We went to university together lolita girls in thongs >:[[[
Comment by Hbqalcbg on 20 September 2011:
I live here Pthc Bbs Forum fyleul
Comment by Wagnvpep on 22 September 2011:
Could you tell me my balance, please? Nude Teen Models :-[[
Comment by Iklnycbi on 24 September 2011:
Could I order a new chequebook, please? Sarka Model Teen
%(