Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Regular Expressions: Valuable Knowledge or Waste of Brain Power?

DZone's Guide to

Regular Expressions: Valuable Knowledge or Waste of Brain Power?

How valuable is it to be a RegEx pro? This story explores what it took to try to explain the concept to a newbie and make on dev re-examine the value of RegEx.

· Java Zone ·
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

I was in a training class this week, covering some of the new features within the MuleSoft Anypoint Design Center.

The training class was being held over WebEx and was running in the PST time zone. Me being in the EST time zone, this made for a late start for the class (11 a.m.) and an even later ending for each day's sessions (after 7 p.m. local time).

Seven members of the CleanSlate Technology Group team, including myself, were attending the training. One individual (let's call him Dave), was very new to the MuleSoft space and had a background in technology that does not include a great deal of programming knowledge.

During the class, the instructor brought up the idea of using regex to enforce validation for a particular element to the API we were jointly creating. The instructor asked that we include the following line in our RAML-based API configuration:

pattern: ^[A-Z]{2,2}[0-9]{2,2}[a-zA-Z0-9]{1,30}$

Initially confused, Dave asked, "What is all that text about?"

Regex Explained... on the Fly

What I found interesting was the dialog that ensued, where some of the other five team members (excluding myself) attempted to explain regular expressions to Dave... in a matter of a few words. Some of those who offered insight had 10+ years of programming experience, while another had just a year of programming experience under his belt. With each attempt, Dave seemed to get further confused and simply decided to accept not understanding the concept.

For the record, this is how Wikipedia defines a regular expression:

"A regular expression is, in theoretical computer science and formal language theory, a sequence of characters that define a search pattern. Usually this pattern is then used by string searching algorithms for "find" or "find and replace" operations on strings."

I added my insight, which is basically to say, "At one time, I really understood regex, but now I simply use Google to locate the right regular expression to meet my situation." I must confess that my response may have been related to working four hours before the 8-hour class started, allowing some slight fatigue to have an impact on my opinion.

Is Knowing Regex Really Worth Your Time ... and Brain Power?

Basically, I decided to let go of my regex knowledge in order to allow other more-valuable elements to remain in the prefrontal cortex of my brain. I realized years ago that Google and StackOverflow are amazing sources for finding the best regular expression for the need being solved. To me, this is no different than memorizing the aspects of an API when nearly every development tool provides the ability to use a dot (.) in order to provide a list of available methods or functions once the object is declared.

So, in my personal view, being a pro at regular expression creation is not a high priority.

What I am not sure of is if my views represent the majority or the minority of our current reader base. As I was driving home from the class, I decided I would create this article to state my views and hope others will provide their comments to compliment or contrast my views.

My core question is: Are you still taking up some of your valuable brain power to maintain regular expression creation ability?

Have a really great day!

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat

Topics:
java ,regular expressions ,api configuration

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}