How to Learn Regular Expressions
Regular Expressions, or RegEx, are used for searching patterns in text. For instance, a RegEx like
iP(hone|ad|od)s? will find mentions of any iOS device in a document. Knowledge of Regular Expressions is essential for programmers, but they can also be an excellent skill for non-developers - people who use Microsoft Word or spend hours inside Google Spreadsheets.
Regular Expressions are extremely powerful, and no less intimidating, but even a basic understanding of RegEx will save you time and make your everyday computing tasks easier.
You can easily extract phone numbers and emails in spreadsheet cells using regex formulas. If you are creating a form in Google Drive, RegEx can help you define validation rules for user input. You can use RegEx in Gmail and Google Analytics too.
How do you learn Regular Expressions? Or, if you are already familiar, how do you take your RegEx skills to the next level? Of course, you will learn by doing, but some excellent tools and learning resources on the Internet will make your journey to knowing Regular Expressions more pleasant.
Lea Verou’s presentation will give you a good overview of what Regular Expressions are and what you can do with them. Jeffrey Friedl’s book - Mastering Regular Expressions - is still the best-printed reference for RegEx newbies and masters. You can explore RegexOne, an interactive Codecademy-like online tutorial for learning RegEx or go here for learning the basics of pattern matching.
RegExr is like a visual playground for Regular Expressions. First, you enter the text in one block and the RegEx in the other. Then, as you edit the RegEx, the matching strings are highlighted in the input text. You can also hover over any character literal in the RegEx to know what it does. RegEx101 is a similar tool that describes your RegEx in English as you write.
Regulex and RegExper are both open-source web apps that make it easy for you to understand and read Regular Expressions. You enter a RegEx, and the tools will create a
Railroad Diagram - for a string to match, it should be able to successfully move from the left of the diagram to the left along one of the available paths.
Windows users can download Expresso, a free program that will help beginners write simple and complex regular expressions through a visual builder. Instead of coding the RegEx manually, you can select the components in a wizard. Reggy for Mac and RegEx Coach for Windows can also help you test regular expressions outside the browser. Also see: How to Learn Coding
Once you understand the basics, head to RegEx Golf](https://regex.alf.nu/) or play this RegEx Crossword to test your skills. Of course, like with everything else, you’ll only learn Regular Expressions by practicing, and mere reading won’t be sufficient.
Google Developer Expert, Google Cloud Champion
Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India.