© 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_7

7. Character Classes

William Yarberry1  
(1)
Kingwood, TX, USA
 

A character class is how RegEx understands which characters should be considered for a match or “anti-match”—anything but what is shown. Note that “class” in this context has nothing to do with the R statement “class(x),” which gives you the class of object x.

Character classes start out simple. Just enclose match characters in brackets. [fk] means select anything containing a “f” or “k.” It does not matter which one is first, and you can have as many letters, numbers, or anything else you need.

A hyphen between two characters indicates ...

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.