XRegExp: An Extended JavaScript Regex Constructor
I have recently written an extended JavaScript regular expression constructor
which I’ve called XRegExp. This script is very small (the minified version weighs in at 937 bytes), and it adds support for two simple but powerful additional flags
beyond those JavaScript supports natively:
- s – Dot matches all (a.k.a.,
single-line) mode.
- x – Free-spacing and comments mode.
It also allows you to use these
flags with the RegExp constructor itself after running one line of code.
Additionally, XRegExp improves some minor cross-browser regex syntax consistency
issues.
Full deets and extensive documentation is available at XRegExp: JavaScript Regular Expression Constructor, or you can just download the script (with comments, or minified).
Regexes built using XRegExp are
identical in speed to those built using the native RegExp constructor, support
all of JavaScript’s regex syntax and regex-related methods, and should work in
JavaScript 1.5+ browsers (tested in IE 5.5–7, Firefox 2, and Opera
9).
Comment Notification
If you would like to receive an email when updates are made to this post, please register here
Subscribe to this post's comments using