Regular Expressions Basics

In this Regular Expression Basics mission, you will learn what regular expressions (regex) are and how you can use them to do some advanced data cleaning in R.

We’ll cover the fundamentals of regular expressions and how they can be used for more powerful string manipulation. You’ll learn about regex concepts such as character classes, quantifiers, capture groups, positional anchors, and more. Then you’ll learn about how to make use of regular expressions in R using the stringr package. This module allows you to easily perform regex operations like searching and replacing text patterns with other text patterns directly in your R code.

In this mission, you will be working with text data from Hacker News, which will give you plenty of practice using regular expressions to tidy up messy text for analysis. You’ll get the opportunity to think like a data scientist as you explore this data set, and by the end of the mission, you will have a working knowledge of regular expressions and how to use them to do powerful string manipulation.

In addition to this mission, you can also check out our Regular Expressions tutorial for extra practice or as a supplementary learning resource!


  • Learn what regular expressions are and how to use them.
  • Learn regex compnents like character classes and quantifiers.
  • Learn how to use Regular Expressions with the stringr package

Lesson Outline

  1. Introduction
  2. The Regular Expression Functions in R
  3. Set of Characters in Regular Expressions
  4. Alternative Patterns
  5. Using Regular Expressions to Select Data
  6. Quantifiers
  7. Character Classes
  8. Accessing the Matching Text with Capture Groups
  9. Negative Character Classes
  10. Word Boundaries
  11. Matching at the Start and End of Strings
  12. Challenge: Using Flags to Modify Regex Patterns
  13. Next Steps
  14. Takeaways

Get started for free

No credit card required.

Or With

By creating an account you agree to accept our terms of use and privacy policy.