Regular Expressions Icon

Regular Expressions

Now you have two problems.
5 Stories
All Topics

JavaScript github.com

A JS library for building regular expressions in (almost) natural language

I’ve seen tools like this one before, but every time I do I still pass them around because regular expressions are powerful but also quite unapproachable. With this library, you can chain together function calls describing how you think about a rule and it’ll generate the expression for you. Example!

const SuperExpressive = require('super-expressive');

const myRegex = SuperExpressive()
  .startOfInput
  .optional.string('0x')
  .capture
    .exactly(4).anyOf
      .range('A', 'F')
      .range('a', 'f')
      .range('0', '9')
    .end()
  .end()
  .endOfInput
  .toRegex();

// Produces the following regular expression:
/^(?:0x)?([A-Fa-f0-9]{4})$/

That matches and captures the value of a 16-bit hexadecmal number like 0xC0D3. Assuming this library generates clean, somewhat optimal expressions (which might be a big assumption), it’s a great way to learn how to write your own expressions over time.

Jan Meppe janmeppe.com

Regex for noobs (like me!)

This is a great introduction to that regex magic!

This blog post is an illustrated guide to regex and aims to provide a gentle introduction for people who never have fiddled with regex, want to, but are kind of intimidated by the whole thing.

If you understand regex it suddenly becomes this super fast and powerful tool … but you first need to understand it, and honestly I find it a bit intimidating for newcomers!

Flavio Copes flaviocopes.com

A guide to JavaScript regular expressions

Flavio Copes:

Learn everything about JavaScript Regular Expressions with this brief guide that summarizes the most important concepts and shows them off with examples.

Regular expressions can be a developer’s best friend or worst nightmare, depending on how well you can wield them. I’ve been using them (with varying degrees of success) since the early aughts, yet I still learn something new every time I read a tutorial like Flavio’s.

0:00 / 0:00