R talk on regular expressions (regex)
Regular expressions are a powerful in any language to manipulate, search, etc. data.
> fruit <- c("apple", "banana", "pear", "pineapple")
 "apple" "banana" "pear" "pineapple"
> grep("a", fruit) # there is an "a" in each of the words
 1 2 3 4
> strsplit("a string", "s") # strsplit splits the string on the "s"
 "a " "tring"
R base has many functions for regular expressions, see slide 9 of Ed's talk below. The package stringr
, created by Hadley Wickham, is a nice alternative that wraps the base regex functions for easier use. I highly recommend stringr.
Ed Goodwin, the coordinator of the Houston R Users group
, gave a presentation to the group last night on regular expressions in R. It was a great talk, and he is allowing me to post his talk here.
Enjoy! And thanks for sharing Ed!
To leave a comment
for the author, please follow the link and comment on his blog: Recology
offers daily e-mail updates
news and tutorials
on topics such as: visualization (ggplot2
), programming (RStudio
, Web Scraping
) statistics (regression
, time series
) and more...
If you got this far, why not subscribe for updates
from the site? Choose your flavor: e-mail
, or facebook