Following the popularity of Verbal Expressions — a library which generates regular expressions by chaining semantic functions together — Andrew Jones reached out to tell us that he has a library in the same spirit as Verbal Expressions that is a little older and more feature rich. He calls it RegExpBuilder and there are currently versions in JavaScript, Dart, Java, and Python.

I asked Andrew to point out a few differences between Verbal Expressions and his offering. He replied,

RegExpBuilder allows you to specify all kinds of quanitites, whereas VerbalExpressions has focused on just a couple of situations (either it might have something, or it does have something). So in RegExpBuilder you can say “it has between 3 and 100″, or it has “at least 7″ or it has “at most 5″ of something. There are all kinds of ways of specifying quantity. Eg:

var regex = new RegExpBuilder()
  .startOfLine()
  .then("thechangelog is ")
  .max(7).of("really ")
  .then("cool")
  .getRegExp();

regex.test("thechangelog is really really really cool"); // true

and,

VerbalExpressions is mostly limited to working with strings. So for example, you pass in “http” to then(“http”), but unless your regular expression is very linear, you will have to deal with groups of patterns, and work with patterns themselves. RegExpBuilder allows you to pass in and work with patterns themselves, so you can do eitherLike(pattern1).orLike(pattern2), for example. Eg:

var pattern = new RegExpBuilder()
  .either("massively ")
  .or("amazingly ");

var regex = new RegExpBuilder()
  .startOfLine()
  .then("thechangelog is ")
  .max(7).like(pattern)
  .then("cool")
  .getRegExp();

regex.test("thechangelog is massively massively massively cool"); // true

and finally,

RegExpBuilder also has support for character classes (like letters, digits, etc), and advanced features like lookaheads

It’s nice to see some friendly competition in this space to push us all to greater heights.

RegExpBuilder is MIT licensed and hosted on GitHub.


Have comments? Send a tweet to @TheChangelog on Twitter.

Subscribe to The Changelog Weekly – our weekly email covering everything that hits our open source radar.