EasyPattern | Human readable RegEx

nadavl@wix.com | May 13th 2013 | JavaScript

Checkout EasyPattern for Javascript and NodeJs!

During some work on our internal tool, I have created EasyPattern, which is a readable alternative to regular expressions.

It is great to match urls with ease, and keep the code super readable and configurable.

For example:

Basic testings

var easyPattern = require("easyPattern");

var pattern = easyPattern("{file}.js");
pattern.test("archive.zip"); // false
pattern.test("index.js"); // true

Basic matching

var pattern = easyPattern("{folder}/{filename}.js");
var result = pattern.match("foo/bar.js");

//result = {folder: "foo", filename: "bar"}

Wildcard matching

var pattern = easyPattern("*.{extension}");
var result = pattern.match("/root/folder/file.exe");

//result = {extension:"exe"}

Advance matching

var pattern = easyPattern("{*}/{filename}?{*}");
var result = pattern.match("www.site.com/home/hello.js?p=1");

//result = {1:"www.site.com/home", 2:"p=1", filename:"hello.js"}

You can download and play with it here


By nadavl@wix.com

Leave a Reply

We are always looking for excellent people. Browse Jobs Here   

At Wix Engineering we develop some of the most innovative cloud-based web applications that influence our 80+ million users worldwide.

Have any questions? Email academy@wix.com.

Find out what’s coming up at Wix Engineering:

Subscribe to our newsletter for updates, events and more.