Question
Regular expression: Write a regular expression to match patterns in the following strings. Demonstratethatyourregularexpressionindeedmatchedthatpatternbyincludingcodesandresults. Carefully review how the rst problem is solved for you. a.
Regular expression: Write a regular expression to match patterns in the following strings. Demonstratethatyourregularexpressionindeedmatchedthatpatternbyincludingcodesandresults. Carefully review how the rst problem is solved for you.
a. We have a vector vText as follows. Write a regular expression that matches g, og, go or ogo in vText and replace the matches with dots.
vText <- c('google','logo','dig', 'blog', 'boogie' )
Answer:
pattern <- 'o?go?'
gsub(pattern, '.', vText)
## [1] "..le" "l." "di." "bl." "bo.ie" b.
b. Replace only the 4 or 6 digit numbers with the word found in the following vector. Please make sure that 3, 5 or 7 digit numbers do not get changed.
vPhone <- c('874','6783','345345', '32120', '468349', '8149674' )
c. Replace all the characters that are not among the 26 English characters or a space. Please replace with an empty spring.
myText <- "#y%o$u @g!o*t t9h(e) so#lu!tio$n c%or_r+e%ct"
d..Extract the numbers (return only integers) that are followed by the units ml or lb in the following text.
myText <- 'At 10am we had 40ml of water, 5 lb of meat, 3lb of salt and 20 apples.'
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started