© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2021
W. YarberryCRAN Recipeshttps://doi.org/10.1007/978-1-4842-6876-6_6

6. Some Simple Patterns

William Yarberry1  
(1)
Kingwood, TX, USA
 
Regular expressions , taken to their extreme, can make you feel irregular. For many R programming tasks, only a few meta-characters need be used. Table 6-1 is from an excellent Loyola Marymount University website.1 In R, the regular expression will be enclosed in quotes and used in one of the seven functions listed in Chapter 9, “The Magnificent Seven.”
Table 6-1

Example regular expressions

Example regular expression

Matches any string that

Hello

Contains {hello}.

gray|grey

Contains {gray, grey}.

gr(a|e)y

Contains {gray, grey}.

gr[ae]y

Get CRAN Recipes: DPLYR, Stringr, Lubridate, and RegEx in R now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.