|Verbal Expressions Are Easier Than Regular Ones|
|Written by Alex Armstrong|
|Monday, 05 August 2013|
This is another of those great ideas that once you have seen you can't understand why it hasn't been invented before. Verbal expressions make use of a fluent interface to specify a match for any target string.
You know how it is. You sit and look at a regular expression and you know what all the parts mean but .... what does it do? Even if you are an expert there are occasions when you miss a symbol or the scope of a symbol. Regular expressions are dense and therefore they are error prone.
There has to be a better way.
Enter Verbal Expressions. No it doesn't do away with regular expressions, it gives you an easier way to create them.
You have methods like startOfLine and then and you can change them together so:
returns a regular expression that matches the string "I Programmer" at the start of a line.
Easy! My favourite Verbal Expression method is maybe(string) which matches the string zero or once. So:
generates a regular expression that finds the string "ISBN" or "ISBN:"
You can take a look at the documentation, which isn't very complete, but the way that Verbal Expressions work is fairly obvious. Notice that the VerEx static object returns a standard regex object which you can use as if you had written the regular expression manually.
It is obvious that if you are a regular expression master then you probably aren't going to be impressed, but for the rest of us mortals it seems like a really easy way to work. The chances of understanding a Verbal Expression after a few weeks of not seeing it are much higher then a dense regular expression.
To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, Facebook, Google+ or Linkedin, or sign up for our weekly newsletter.
or email your comment to: email@example.com
|Last Updated ( Tuesday, 06 August 2013 )|