Closed lisaoshita closed 7 years ago
So the str_view function allows you to see the results of what matches in the right hand side in an html viewer. So try this code and notice what is gray and what is white. The argument for match was changed to NA so you can see what does and does not match.
x <- c("Cat", "CAT", "cAt", "dog", "gerbil") str_view(x, regex("cat", ignore_case = TRUE), match = NA)
If you want the matching results as an object that you can work with, try using str_detect instead.
str_detect(x, regex("cat", ignore_case = TRUE))
Hmm, I'm still getting the same output and str_detect returns all false
Maybe you need to load the stringr package first? Or, try updating R and the stringr
package.
Here's what I get:
And changing the option to match = NA
:
I ended up reinstalling all of the packages and it worked. Thanks!
I’m practicing with product classification, and I wanted to search through the device variable and classify phones in one category. But the cases aren’t consistent, some are uppercase and some are lowercase, so I wanted to use the regex function to allow for case-insensitive matching. But calling regex in r doesn’t seem to work for me. I’ve copied and pasted the code used in the Data camp lesson to r and that doesn’t output the same either- it doesn’t recognize any patterns. I can’t figure this one out
This is the code that I copied and pasted from Data Camp. R doesn't match any patterns with this
x <- c("Cat", "CAT", "cAt")
str_view(x, regex("cat", ignore_case = TRUE), match = TRUE)