---
layout: post
title: "How to write a simple regular expression with R using sub and str_replace (CC183)"
blurb: "Basic regular expressions in R"
author: "PD Schloss"
date: 2022-01-31 11:00
comments: false
youtube: 3toJ2LhvEfw
start_hash: c7b0cc2f1a109885f24bac712bd7b78ee912ad45
end_hash: 310ff4a1141e0a460bc6228bda0585cb87d4db11
---

A regular expression is a pattern that you want to search for and do something with. R has a variety of tools for creating regular expressions that allow you to maniuplate text. In this episode we'll see the similarities and differences between sub and str_replace and how they differ from gsub and str_replace_all. We'll introduce metacharacters and quantifiers. This is part of a series of videos demonstrating how to functions from base R to make these data compatible with tools from the tidyverse


<iframe style="margin: 0 auto;display:block;" width="560" height="315" src="https://www.youtube.com/embed/{{ page.youtube }}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>


## Code

You can browse the state of the repository at the
* [beginning of the episode](https://github.com/riffomonas/distances/tree/{{ page.start_hash }})
* [end of the episode](https://github.com/riffomonas/distances/tree/{{ page.end_hash }})
