Regexes Got Good: The History and Future of Regular Expressions in JavaScript

Over at Smashing Magazine, I just published a 3,100-word (no fluff) article evaluating the history, present state, and future of regexes in JavaScript, with lots of tips. I think all JavaScript developers will learn something from this, and I'd love to know what was new for you!

Check it out: Regexes Got Good: The History And Future Of Regular Expressions In JavaScript.

article screenshot

Launching: ‘regex’ template tag and Regex Colorizer v1

I've recently released two new open source regex libraries.

regex

regex is a template tag for dynamically creating readable, high performance, native JavaScript regular expressions with best practices built-in and advanced features. It's lightweight, has no dependencies, and supports all ES2024+ regex features.

Highlights include using whitespace and comments in regexes, atomic groups via (?>…) which can help you avoid ReDoS, subroutines and subroutine definition groups which enable powerful subpattern composition, and context-aware interpolation of RegExp instances, escaped strings, and partial patterns.

Run npm install regex in your JavaScript project and then simply import {regex} from 'regex' to get started. Check out examples and more on GitHub.

Regex Colorizer 1.0

Regex Colorizer is a project that highlights regex syntax, for use in blogs, docs, and regex tools. I created it for old-school RegexPal back in 2007, but it hadn't received any updates since 2010. Until now. Version 1.0 is a significant update that improves its API and adds support for modern JavaScript regex syntax and flags. Check out the demo!

Awesome Regex: The best regex resources for all major regex flavors

Awesome Regex logo

I created a curated list on GitHub of the best regular expression tools, tutorials, libraries, and many other resources. It covers all major regex flavors, and currently includes especially deep coverage of regular expressions in JavaScript (including a concise history of all regex features added to JavaScript in ES6 through ES2024, plus active proposals for the future).

Check it out, and return to it easily with a handy shortcut URL: regex.cool.

Regex & Facebook Experience Tech Talk

I recently gave a talk for a group of university students studying web development in Belgrade, Serbia. In it, I talked about my background, my experience starting in tech and eventually working at Facebook for seven years, and (most relevant to this blog) I spent about 20 minutes showing off some cool and advanced regular expressions. Specifically, regexes for switching Fahrenheit to Celsius, deleting repeated words, deleting non-adjacent duplicate lines, checking password complexity, reformatting names, adding thousands separators, matching balanced parentheses, and matching palindromes.

You can find the video and slides here (Lecture at SAE Belgrade: Lessons from Facebook) or you can watch the video on YouTube (with the regex portion starting at 52:26).

XRegExp 3.0.0!

After 3+ years, XRegExp 3.0.0 has been released. Standout features are dramatically better performance (many common operations are 2x to 50x faster) and support for full 21-bit Unicode (thanks to Mathias Bynens). I’ve also just finished updating all the documentation on xregexp.com so go check that out. 🙂

If you haven’t used XRegExp before, it’s an MIT licensed JavaScript library that provides augmented (and extensible!) regular expressions. You get new modern syntax and flags beyond what browsers support natively. XRegExp is also a regex utility belt with tools to make your client-side grepping and parsing easier, while freeing you from worrying about pesky cross-browser inconsistencies and things like manually manipulating lastIndex or slicing strings when tokenizing.

Version 3.0.0 has lots of additional features, options, fine tuning, cross-browser fixes, some new simplified syntax, and thousands of new tests. And it still supports all the browsers. Check out the long list of changes. There are a few minor breaking changes that shouldn’t affect most people and have easy workarounds. I’ve listed them all below, but see the full changelog if you need more details about them.

  • XRegExp.forEach no longer accepts or returns its context. Use binding with the provided callback instead.
  • Moved character data for Unicode category L (Letter) from Unicode Base to Unicode Categories. This has no effect if you’re already using Unicode Categories or XRegExp-All.
  • Using the same name for multiple named capturing groups in a single regex is now a SyntaxError.
  • Removed the 'all' shortcut used by XRegExp.install/uninstall.
  • Removed the Prototypes addon, which added methods apply, call, forEach, globalize, xexec, and xtest to XRegExp.prototype. These were all just aliases of methods on the XRegExp object.
  • A few changes affect custom addons only: changed the format for providing custom Unicode data, replaced XRegExp.addToken’s trigger and customFlags options with new flag and optionalFlags options, and removed the this.hasFlag function previously available within token definition functions.

You can download the new release on GitHub or install via npm. I’d love to hear feedback and common regex-related use cases that you think could be simplified via new XRegExp features. Let me know here or in GitHub issues. Thanks!