Question 3

raw.data <-"555-1239Moe Szyslak(636) 555-0113Burns, C. Montgomery555-6542Rev. Timothy Lovejoy555 8904Ned Flanders636-555-3226Simpson, Homer5553642Dr. Julius Hibbert"
names <- data.frame(matrix(vector(), 6, 5,
                dimnames=list(c(), c("name","first_name","last_name","middle_name","title"))),
                stringsAsFactors=F)
names$name <- unlist(str_extract_all(raw.data, pattern = "\\D+[A-z]"), use.names=FALSE)
names$middle_name <- FALSE
names$title <- FALSE

for (i in 1:length(names$name)){
  #first name last name
  if (str_detect(names$name, pattern="[[:punct:]]")[i] == FALSE){
    name1 <- unlist(str_extract_all(names$name[i], pattern = "[A-z]+"), use.names=FALSE)
    names$first_name[i] <- name1[1]
    names$last_name[i] <- name1[2]
  }
  
  #lastname, first name no middle name
  if(str_detect(names$name, pattern="([A-z]+,\\s+[A-z]+)(?!.)")[i] == TRUE){
    name1 <- unlist(str_extract_all(names$name[i], pattern = "[A-z]+"), use.names=FALSE)
    names$first_name[i] <- name1[2]
    names$last_name[i] <- name1[1]
  }
  
  # last name, m. first name
  if (str_detect(names$name, pattern=",")[i] == TRUE && str_detect(names$name, pattern="\\.")[i] == TRUE) {
    names$middle_name[i] <- TRUE
    name1 <- unlist(str_extract_all(names$name[i], pattern = "[A-z]+"), use.names=FALSE)
    names$first_name[i] <- name1[3]
    names$last_name[i] <- name1[1]
  }
  # title first name last name
  if (str_detect(names$name, pattern=",")[i] == FALSE && str_detect(names$name, pattern="\\.")[i] == TRUE) {
    names$title[i] <- TRUE
    name1 <- unlist(str_extract_all(names$name[i], pattern = "[A-z]+"), use.names=FALSE)
    names$first_name[i] <- name1[2]
    names$last_name[i] <- name1[3]
  }  
}
datatable(names)

Question 4

# [0-9]+\\$:
# Matches any string of number that is followed by a dollar sign character. Example: "40$".
# \\b[a-z]{1,4}\\b
# Matches any one to four letter lowercase word that starts or ends with any non-word character (excluding spaces and punctuation). Example: All the words in this sentence will match: "the dog ran over the hill".
# .*?\\.txt$
# Matches any phrase with a .txt extension and .txt has to be the end of the string. Example: "file.txt" is a match.
# \\d{2}/\\d{2}/\\d{4}
# Matches a date (or series of numbers) using format dd/mm/yyyy or mm/dd/yyyy. Example: "02/17/2019".
# <(.+?)>.</\\1>
# Matches a html open and close tags with on character in them. Example: "<html> </html>".

Question 9

string <- "clcopCow1zmstc087wnkig7OvdicpNuggvhyn92Gjuwczi8hqrfpRxs5Aj5dwpn0TanwoUwisdij7Lj8kpf03AT5Idr3coc0bt7yczjatOaootj55t3Nj3ne6c4Sfek.r1w1Yww0jigOd6vrfUrbz2.2bkAnbhzgv4R9i05zEcrop.wAgnb.SqoU65fPa1otfb7wEm24k6t3sR9zqe5fy89n6Nd5t9kc4fE905gmc4Rgxo5nhDk!gr"
#Congratulations you are a super nerd
code <- unlist(str_extract_all(string, pattern = "[^\\.]+"), use.names = FALSE)

for (i in 1:length(code)) {
  decode <- str_extract_all(code[i], pattern = "[A-Z]|!")
  code[i] = paste(unlist(decode), collapse ="")
}
paste(code, collapse = " ")
## [1] "CONGRATULATIONS YOU ARE A SUPERNERD!"