Creating an advanced regular expression in R with str_replace and separate (CC184)
Channel: Riffomonas Project
Date: 2022-02-03

R has a very powerful set of features for building and using a regular expression. In this episode we move beyond the basics and discuss anchors, universal and specific metacharacters, and how to specify groups within a pattern that you can use in the replacement value. Finally, we'll use all this with the separate function. We'll do all this in RStudio using the stringr package.

You can find my blog post for this episode at https://www.riffomonas.org/code_club/2022-02-03-adv-regex.

The data were generated in our Kozich et al. 2013 paper (http://doi.org/10.1128/AEM.01043-13) using samples from the Schloss et al. 2012 paper (http://doi.org/10.4161/gmic.21008).

#str_replace #regex #R #Rstudio #Rstats

Want more practice on the concepts covered in Code Club? You can sign up for my weekly newsletter at https://shop.riffomonas.org/youtube to get practice problems, tips, and insights.

If you're interested in taking an upcoming 3 day R workshop be sure to check out our schedule at https://riffomonas.org/workshops/

You can also find complete tutorials for learning R with the tidyverse using...
Microbial ecology data: https://www.riffomonas.org/minimalR/
General data: https://www.riffomonas.org/generalR/

0:00 Advanced regular expressions in R
2:08 Using the + quantifier in regular expressions
3:17 Using anchors in regular expressions
4:27 Saving and reusing parts of the pattern
5:57 Universal and super specific metacharacters
7:10 Advanced use of parentheses
7:43 Putting it all together
8:53 Trying a different approach with str_replace and separate