Question: Problem 7 (20 pts): Please answer following questions a) Please provide a regular expression for which the following sentences either match or not match Match:

Problem 7 (20 pts): Please answer following questions

a) Please provide a regular expression for which the following sentences either match or not match

Match:

bad habit

good, because there is nothing worse than a man in kinky underwear

Badcop, it is because people want to use drugs

Good Monday Holiday

Is it really good?

Yes, it is really Good.

But NOT match:

It is not that bad or good, it is fine.

habit

because there is nothing worse than a man in kinky underwear

it is because people want to use drugs

Monday Holiday

Is it real?

b) Please provide a regular expression to match all the following telephone numbers

saved in the following variable:

phones <- c("2197338965", "+1 219 733 8965", " 219 733 8965", "329-293-8753 ",

"595 794 7569", "387 287 6718", "233.398.9187 ", "482 952 3315", "Work: 579-499-

7527", "Home:543.355.3679")

Page 10 of 10

c) Suppose state.name is a vector variable storing the state names. Please write an R

command to get the state names, which are ended with a. The command should return

the state names (values) rather than the indexes.

d) Please underscore the characters, if any, that match the pattern specified by the regular

expression [Gg]eorge( [Ww].)? [Bb]ush in the following sentences,

i bet i can spell better than you and george bush combined

I met with George W Bush yesterday

BBC reported that President George W. Bush claimed God told him to invade Iraq

a bird in the hand is worth two george bushes

Another man is named George Ww. Bush

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!