Question 1

q1_ans <- majors %>%
  filter(grepl("DATA", Major) | grepl("STATISTICS", Major))
q1_ans
## # A tibble: 3 × 3
##   FOD1P Major                                         Major_Category         
##   <chr> <chr>                                         <chr>                  
## 1 6212  MANAGEMENT INFORMATION SYSTEMS AND STATISTICS Business               
## 2 2101  COMPUTER PROGRAMMING AND DATA PROCESSING      Computers & Mathematics
## 3 3702  STATISTICS AND DECISION SCIENCE               Computers & Mathematics

Question 2

#Loads fruit list
fruit_list <- '[1] "bell pepper"  "bilberry"     "blackberry"   "blood orange"
[5] "blueberry"    "cantaloupe"   "chili pepper" "cloudberry"  
[9] "elderberry"   "lime"         "lychee"       "mulberry"    
[13] "olive"        "salal berry"'

patternf <- "\"(.*?)\""

q2_ans <- str_extract_all(fruit_list, patternf)
# Turns the list info a vector
q2_ans <- unlist(q2_ans)
q2_ans <- gsub('\\"', "", q2_ans)
print(q2_ans)
##  [1] "bell pepper"  "bilberry"     "blackberry"   "blood orange" "blueberry"   
##  [6] "cantaloupe"   "chili pepper" "cloudberry"   "elderberry"   "lime"        
## [11] "lychee"       "mulberry"     "olive"        "salal berry"

Question 3

#For testing
text <- 'abccbalkjsdoihfoie'
pattern1 <- '(.)(.)(.).*\\3\\2\\1'

q3_ans <- regmatches(text, gregexpr(pattern1, text))
q3_ans
## [[1]]
## [1] "abccba"

Question 4

#For testing
text <- 'bobo bo kokoko'

regex_1 <- "\\b(\\w)\\w*\\1\\b"
#//b denotes the limits of the word
#(\\w) denotes the first character of the word
#\\w* represents all following character
#\\1 means that the last character should be the same as the first character
regex_2 <- "\\b\\w*(\\w\\w)\\w*\\1\\w*\\b"
#//b denotes the limits of the word
#\\w* denotes any character (or none) before the two sets of character
#(\\w\\w) represents the two characters
regex_3 <- "\\b\\w*(\\w)\\w*\\1\\w*\\1\\w*\\b"

q4_ans <- regmatches(text, gregexpr(regex_3, text))
q4_ans
## [[1]]
## [1] "kokoko"