Regular expressions can be used to search and match different complex parts of text. But is there something we can do to improve the technology that's been around from the 1950's?
This is the backstory of a small weekend project that grew into multiple thousand star trending repository.
Regular expressions are hard
The language used to express the part of a text can get pretty hard to read pretty fast, obfuscating the bigger view of what a person might have wanted to accomplish.
Consider this, rather simple, regular expression:
So what does it do? When we have a look with a magnificent tool called Regexper, we can begin to make some sense about it:
Ok, this looks a bit more readable. You might even start to tell that the expression has something to do with emails.
But you might want to be able to make the regular expressions readable without needing to copy-paste them to a website. VerbalExpressions to the rescue!
How to use VerbalExpressions?
VerbalExpressions is a small library that you can include to your project so you can use more expressive language. For example the previous line could be expressed like this:
VerEx().startOfLine() .somethingBut(' ') .then('@') .somethingBut(' ') .then('.') .somethingBut(' ') .endOfLine();
This helps you to understand what is going on, because the script chains up the regular expression nicely as you read it line by line.
Converting to RegExp
Using VerbalExpressions can help if you're trying to learn to use the "real" regular expressions, because the VerEx object is just an extension of the underlying
You can do everything with the
VerEx object you'd do with a regular
RegExp object; you can find, test, replace etc.
You can even convert the
VerEx object to a regular
RegExp object by calling the
var fooFinder = VerEx().find('foo').toRegExp(); console.log(fooFinder); /* Prints /(?:foo)/gm */
So you can just start coding and see how the underlying regular expression grows.
The rest is history
After publishing the initial version of VerbalExpressions, I posted it to a couple of places in hope that it'd get some interest from developers struggling with learning regular expressions.
Fortunately things worked out much better. With the help of a fellow developer, we got a big publicity after the Smashing magazine tweeted about the library:
Interesting: VerbalExpressions is a JS librarty that helps to construct hard regular expressions: https://t.co/hb55xgJAxp (via @luotojesse)— Smashing Magazine (@smashingmag) July 21, 2013
This got a nice boost of a publicity for a weekend project; I instantly saw rising number of stars in the GitHub repository.
Sometimes all it takes is a little nudge to get something started. In few hours there was enough stars for the project to rise to the GitHub's daily trending repositories, and eventually to the weekly trending list, where more and more people started to get familiar with the repository.
In a few days the repository had grown from a tiny weekend project to a full, active open source library. But only after people started porting the library to other languages, the project needed to become its own GitHub organization.
From there on things just grew wildly organically. Someone made a logo, someone crafted a github.io page. And other people kept porting the library to different languages.
Fast-forward to late 2015, the VerbalExpressions has been ported to 23 languages, including common ones like Java and Python, but also to less-common languages like Qt and Racket.
Future of VerbalExpressions?
As I love making tools for developers, I think VerbalExpressions has been one of my most successful projects so far. But as the number of ports grew explosively, the maintenance of the whole project became a monster.
Like most of the personal projects, VerbalExpressions has been left, for now, to its current state because of the lack of personal time.
If you'd like to team up to brainstorm about the future of the project, go ahead and send me a tweet; it would be great to change thoughts about the direction of the project!
One more thing...
Thank you for reading this blog post. The content on this blog will always be free, but I started an experiment a while ago to accept donations. So if you think the blog post was good, you can buy me a cup of coffee. Any thoughts? Ping me on twitter and let me know!