Flagrant Badassery

A JavaScript and regular expression centric blog

Archive for February, 2007

parseUri: Split URLs in JavaScript

Update: The following post is outdated. See parseUri 1.2 for the latest, greatest version. For fun, I spent the 10 minutes needed to convert my parseUri() ColdFusion UDF into a JavaScript function. For those who haven't already seen it, I'll repeat my explanation from the other post… parseUri() splits any well-formed URI into its parts […]

Read More

Regexes in Depth: Advanced Quoted String Matching

In my previous post, one of the examples I used of when capturing groups are appropriate demonstrated how to match quoted strings: (["'])(?:\\\1|.)*?\1 (Note: This has some issues. See Edit 2, at the end of this post, if you intend to use this in an application.) To recap, that will match values enclosed in either […]

Read More

Capturing vs. Non-Capturing Groups

I near-religiously use non-capturing groups whenever I do not need to reference a group's contents. Recently, several people have asked me why this is, so here are the reasons: Capturing groups negatively impact performance. The performance hit may be tiny, especially when working with small strings, but it's there. When you need to use several […]

Read More

More URI-Related UDFs

To follow up my parseUri() function, here are several more UDFs I've written recently to help with URI management: getPageUri() Returns a struct containing the relative and absolute URIs of the current page. The difference between getPageUri().relative and CGI.SCRIPT_NAME is that the former will include the query string, if present. matchUri(testUri, [masterUri]) Returns a Boolean […]

Read More

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 […]

Read More