Friday, August 1st, 2008 •
Related •
Filed Under
I've released a simple plugin for XRegExp (my JavaScript regex library) that adds support for Unicode properties and blocks to JavaScript regular expressions. It uses the Unicode 5.1 character database, which is the very latest version.
The Unicode plugin enables the following Unicode properties/categories in any XRegExp:
\p{L} — Letter
\p{M} — Mark
\p{N} — Number
\p{P} — Punctuation
\p{S} — [...]
Read More
Thursday, June 12th, 2008 •
Related •
Filed Under
How many times have you needed to run multiple replacement operations on the same string? It's not too bad, but can get a bit tedious if you write code like this a lot.
str = str.
replace( /&(?!#?\w+;)/g , '&' ).
replace( /"([^"]*)"/g , '“$1”' ).
replace( /</g [...]
Read More
Saturday, May 31st, 2008 •
Related •
Filed Under
I'm excited to announce that I've recently started working on a regular expression book for O'Reilly Media. The back story is that a few months ago, Jeffrey Friedl (author of the world's best regular expression book yet ) was kind enough to introduce me to his editor at O'Reilly, Andy Oram. After Andy and I [...]
Read More
Thursday, May 29th, 2008 •
Related •
Filed Under
A few months ago Ben Nadel (a regex fan and prominent ColdFusion blogger) asked me if I was interested in promoting his idea for a "National Regular Expression Day," where he'd give away some shirts and books and basically just have some fun with regex evangelism. Well, Ben finally kicked if off, assigning the honor [...]
Read More
Wednesday, May 28th, 2008 •
Related •
Filed Under
Here's a neat little trick I came up with for removing nested patterns from a string.
var str = "abc<1<2<>3>4>def";
while (str != (str = str.replace(/<[^<>]*>/g, "")));
// str -> "abcdef"
Notice that the regex in this one-liner doesn't try to deal with nested patterns at all. The while loop's condition replaces instances of <…> (where angled brackets are [...]
Read More