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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!