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 , '<' ). replace( />/g , '>' […]
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 <…> […]
Read More
Friday, May 16th, 2008 •
Related •
Filed Under
Cüneyt Yılmaz's JRX is a cool JavaScript regex tester inspired by the RX tool of Komodo IDE. Cüneyt recently added my XRegExp library to his tester, so JRX is now a nice and easy way to test XRegExp's singleline and extended modes, as well as named capture and other XRegExp-provided syntax. Check it out! As […]
Read More
Sunday, April 20th, 2008 •
Related •
Filed Under
Update: This version of XRegExp is outdated. See XRegExp.com for the latest, greatest version. If you haven't seen the prior versions, XRegExp is an MIT-licensed JavaScript library that provides an augmented, cross-browser implementation of regular expressions, including support for additional modifiers and syntax. Several convenience methods and a new, powerful recursive-construct parser that uses regex […]
Read More
Sunday, April 13th, 2008 •
Related •
Filed Under
The bottom line of this blog post is that Internet Explorer incorrectly increments a regex object's lastIndex property after a successful, zero-length match. However, for anyone who isn't sure what I'm talking about or is interested in how to work around the problem, I'll describe the issue with examples of iterating over each match in […]
Read More