For example is an anchor that indicates the literal

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: •  •  Look at each character Check to see if it is “S” If it is, then look at the next character(s) This is the idea behind regular expressions The regular expression “St ” is made up of three literal characters. The regular expression matching engine does something very similar to what we just did. The Slippery St Frances! || ||| ! Found S________|| |||! Followed by t?__| No ||| ! Is it S?________| No ...||| Keep looking for S! Found S_________________|||! Followed by t?___________|| Yes! Followed by a blank?______| Yes - A match!! Luckily, we don’t actually need to write our own func+ons for replacement. The R func+ons gsub() and sub() look for a paMern and replace it within a string with some other text. The “g” in gsub() refers to global. It changes all the matches, whereas sub() only replaces the first match (in each element – both gsub() and su...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online