1. [0-9]+\$ Type of String: Character Classes of [0-9] with Quantifier + (matched One or more times) ignoring the Metacharacter $ using \ as \$

Example as Shown below:

library (stringr)
## Warning: package 'stringr' was built under R version 3.2.2
str_extract("1234$ is a asdasdas dsadas$ $12345 3456$ 57648", "[0-9]+\\$")
## [1] "1234$"
str_extract_all("1234$ is a asdasdas dsadas$ $12345 3456$ 57648", "[0-9]+\\$")
## [[1]]
## [1] "1234$" "3456$"

b)\b[a-z]{1,4}\b Type of String: Anchor Sequence in R to match a word boundary \b and matches with Regex character classes of any lower case ASCII letter [a-z] with Quantifier {1,4} which means precending items will match atleast 1 time but not more than 4 times

expb="123 is the way to DO anything unIque AND make amazing things"
str_extract(expb,"\\b[a-z]{1,4}\\b")
## [1] "is"
str_extract_all(expb,"\\b[a-z]{1,4}\\b")
## [[1]]
## [1] "is"   "the"  "way"  "to"   "make"

c).?\.txt$ Type of String: Quantifier means preceding item will be matched zero or more times and ? means preceding items is optional and will be matched atmost once. So any character ahead of . metacharacter as .txt will be considered

str_extract("adas asdasd adasd _txt", ".*?\\.txt$")
## [1] NA
str_extract("Iamhere.txt",".*?\\.txt$")
## [1] "Iamhere.txt"
  1. \d{2}/\d{2}/\d{4} Type of String: This is a Achor sequence which will match a digit in a specfic format as shown here having {2} digits /{2} digit/{4} digit which is in date format
str_extract("12\12\2012","\\d{2}/\\d{2}/\\d{4}")
## [1] NA
str_extract("12/12/2012","\\d{2}/\\d{2}/\\d{4}")
## [1] "12/12/2012"

e)<(.+?)>.+?

str_extract("<font> </head>","<(.+?)>.+?</\\1>")
## [1] NA
str_extract("<font>I am an awesome font</font>","<(.+?)>.+?</\\1>")
## [1] "<font>I am an awesome font</font>"
str_extract("<HTml>AM I correct </html>","<(.+?)>.+?</\\1>")
## [1] NA
  1. Rewrite the expression [0-9]+\$ in a way that all elements are altered but the expression performs the same task
str_extract("1234$ is a asdasdas dsadas$ $12345 3456$ 57648", "\\d{1,}[$]")
## [1] "1234$"
str_extract_all("1234$ is a asdasdas dsadas$ $12345 3456$ 57648", "\\d{1,}[$]")
## [[1]]
## [1] "1234$" "3456$"
  1. Consider the mail address chunkylover53[at]aol[dot]com a.Transform the string to a standard mail format using regular expressions
emailID="chunkylover53[at]aol[dot]com"
emailID=sub("\\[at]","@",emailID)
emailID=sub("\\[dot]",".",emailID)
emailID
## [1] "chunkylover53@aol.com"
  1. Imagine we are trying to extract the digits in the mail address. To do so we write the expression [:digit:]. Explain why this fails and correct the expression. Answer: Failed because of Wrong syntax. Correct expression is [[:digit:]]
str_extract_all("chunkylover53[at]aol[dot]com","[[:digit:]]{1,}")
## [[1]]
## [1] "53"

c.Instead of using the predefined character classes, we would like to use the predefined symbols to extract the digits in the mail address. To do so we write the expression \D. Explain why this fails and correct the expression. Answer: Failed because of Wrong syntax. \D is for non digit characters and for digit charaters we use \d

str_extract_all("chunkylover53[at]aol[dot]com","\\d{1,}")
## [[1]]
## [1] "53"