Using the github link, we import the data from github
majors <- read.csv("https://raw.githubusercontent.com/fivethirtyeight/data/master/college-majors/majors-list.csv")
Creaty a vector out of the majors column
major_vec<- as.vector(majors$Major)
From this vector we can run a quick search using | to depict or and ask r to show us majors from the vector maatching DATA or STAtistics
grep('DATA|STATISTICS', major_vec, value= TRUE)
## [1] "MANAGEMENT INFORMATION SYSTEMS AND STATISTICS"
## [2] "COMPUTER PROGRAMMING AND DATA PROCESSING"
## [3] "STATISTICS AND DECISION SCIENCE"
Adding commas to delineate each string in the list helps r properly create a vector
Vegetables <- c("bell pepper", "bilberry", "blackberry", "blood orange", "blueberry", "cantaloupe", "chili pepper", "cloudberry", "elderberry" , "lime", "lychee", "mulberry" , "olive" , "salal berry")
(.)\1\1 : This regex will match any expressions as the backslashes are not escaped and the regx is not encased in quotes
“(.)(.)\2\1” : This regex will return 4 letters in a palindrome format where the firs 2 letters are repeated backwards e.g abba, otto, iddo
(..)\1 : This regex will match any expressions as the backslashes are not escaped and the regx is not encased in quotes
“(.).\1.\1” : This regex will match any expressions where the first letter is repeated 3 times with one character separating each iteration of the letter eg Bababa
“(.)(.)(.).*\3\2\1” : Thie regex will match any expression where the first three letters are repeated at backwards with any number of characters in between them e.g reviver, abccba
sample_words <- c("church", "character", "banana","dad", "mom", "eleven", "bababa", "pepper")
Regex for words that start and end with the same character
str_view(sample_words, "^(.).*\\1$")
## [4] | <dad>
## [5] | <mom>
Regex for words that contain a repeated pair of letters
str_view(sample_words, "(..).*\\1")
## [1] | <church>
## [3] | b<anan>a
## [7] | <bababa>
## [8] | <peppe>r
Regex for word that contains one letter in at least 3 places
str_view(sample_words, "(a.*){3,}")
## [3] | b<anana>
## [7] | b<ababa>