Hi everyone!

All of us love to decrease the time spent with mechanical or repetitive tasks. Isn’t it? And, Regular Expressions certainly can help us with that. Let’s talk a little bit about it.

What is it?

In a caveman definition, a Regular Expression is a tool that can help us in search-and-replace operations, validation of text data, parsing and manipulating text, etc. From now, I’ll use RegEx to refer to Regular Expression.

How does it work?

RegEx does all the stuff mentioned before, specifying a kind of text pattern using a combination of characters and/or metacharacters. These last ones are symbols that have a special meaning, for instance, the symbol “\”, as a metacharacter, means that we want to escape a character that already has a specific meaning in a certain context, that is, change the way how the character is interpreted, when it is different from what we expect.

Practical example

I was searching for a price table of design services and I found an interesting one, but it was a little disorganized. So, I decided to organize it and I certainly did not want to spend time doing this manually. I wrote a RegEx that organized the text into four content categories: item description, unit, quantity, and price.

=REGEXEXTRACT(A3;”([^(unidade)].*?)(un.*?)(\d+)(.*?,00)”)

Metacharacters

Metacharacters can vary accordingly to the programming language or software used to apply RegEx. So, the best way to get into RegEx is by studying directly in the technology you choose to use, I believe. However, I’ll show some metacharacters with some explanation.

Until the next article!

Further reading

  • Introducing Regular Expressions by Michael Fitzgerald. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
  • Mastering Regular Expressions, Third Edition by Jeffrey E. F. Friedl. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
  • Regular Expressions Cookbook, Second Edition by Jan Goyvaerts and Steven Levithan. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.