Flagrant Badassery

A JavaScript and regular expression centric blog

Archive for June, 2007

parseUri 1.2: Split URLs in JavaScript

I've just updated parseUri. If you haven't seen the older version, parseUri is a function which splits any well-formed URI into its parts, all of which are optional. Its combination of accuracy, flexibility, and brevity is unrivaled. Highlights: Comprehensively splits URIs, including splitting the query string into key/value pairs. (Enhanced) Two parsing modes: loose and […]

Read More

Levels of JavaScript Regex Knowledge

N00b Thinks "regular expressions" is open mic night at a poetry bar. Uses \w, \d, \s, and other shorthand classes purely by accident if at all. Painfully misuses * and especially .*. Puts words in character classes. Uses | in character classes for alternation. Hasn't heard of the exec method. Copies and pastes poorly written […]

Read More

JavaScript split Bugs: Fixed!

The String.prototype.split method is very handy, so it's a shame that if you use a regular expression as its delimiter, the results can be so wildly different cross-browser that odds are you've just introduced bugs into your code (unless you know precisely what kind of data you're working with and are able to avoid the […]

Read More

Mimicking Lookbehind in JavaScript

Unlike lookaheads, JavaScript doesn't support regex lookbehind syntax. That's unfortunate, but I'm not content with just resigning to that fact. Following are three ways I've come up with to mimic lookbehinds in JavaScript. For those not familar with the concept of lookbehinds, they are zero-width assertions which, like the more specific \b, ^, and $ […]

Read More

Commafy Numbers

I've never used the few scripts I've seen that add commas to numbers because usually I want to apply the functionality to entire blocks of text. Having to pull out numbers, add commas, then put them back becomes a needlessly complex task without a method which can just do this in one shot. So, here's […]

Read More