How to Learn Regular Expressions

Published in: Code - 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 be a great skill to have for non-developers as well - people who use Microsoft Word or spend hours inside Google Spreadsheets.

RegEx in Microsoft Word

Why Learn Regular Expressions?

Regular Expressions are extremely powerful, and no less intimidating, but even basic understanding of RegEx will save you time and make your everyday computing tasks easier.

For instance, you can quickly find & replace text that matches complex patterns in Word or Vim. 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? You will obviously learn by doing but there are some excellent tools and learning resources on the Internet that will take make your journey to knowing Regular Expressions more pleasant.

The Best RegEx Tools & Resources

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.

Highlighting all the non-English characters Highlighting all the non-English characters

RegExr is like a visual playground for Regular Expressions. You enter the text in one block and the RegEx in the other. 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 also 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 left of the diagram all the way to the left along one of the available paths.

RegEx Visualizer

Windows users can download Expresso, a free program that will help beginners write both 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 over to RegEx Golf or play this RegEx Crossword to test your skills. Like with everything else, you’ll only learn Regular Expressions by practicing and mere reading won’t be sufficient.

📮  Subscribe to our Email Newsletter for Google tips and tutorials!
Published in: Code - Regular Expressions

Looking for something? Find here!

Meet the Author

Web Geek, Google Developer Expert
Amit Agarwal

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. He is the developer of Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

Get in touch

Google Add-ons

Do more with your Gmail and GSuite account

We build bespoke solutions that use the capabilities and the features of Google Workspace for automating business processes and driving work productivity.

  1. Mail Merge with Attachments
    Send personalized email to your Google Contact with a Google Sheet and Gmail
  2. Save Emails and Attachments
    Download email messages and file attachments from Gmail to your Google Drive
  3. Google Forms Email Notifications
    Send email notifications to multiple people when a new Google Form is submitted
  4. Document Studio
    Create beautiful pixel perfect documents merging data from Google Sheets and Google Forms
  5. Creator Studio for Google Slides
    Turn your Google Slides presentations into animated GIFs and videos for uploading to YouTube