From the course: R for Data Science: Lunch Break Lessons

Unlock this course with a free trial

Join today to access over 22,700 courses taught by industry experts.

Use regular expressions with regexpr() and gregexpr()

Use regular expressions with regexpr() and gregexpr()

From the course: R for Data Science: Lunch Break Lessons

Use regular expressions with regexpr() and gregexpr()

- [Instructor] Let's take a look at the very confusing world of regular expressions. If you don't have any experience with regular expressions, I highly recommend you take one of the courses in this library on programming regular expressions. It can be confusing and you need to practice a bit in order to fully understand how it works, but for the sake of this experiment, let's define a vector, we'll call it someText. And let's take a quick look at that vector. It has two lines. One of them was "Twas brillig and the blithey toves", and the other one is "I brought 15 apples to the market." Let's suppose that we want to find the position of any word that begins with B in either one of those lines. Well, for that, I can use regexpr. Now I'm going to give it a regular expression. I'm going to say, any word that starts with B, and backslash backslash w indicates a word boundary and one or more characters. I want to search through…

Contents