Exercise

Ignoring case when matching

Rather than transforming the input strings, another approach is to specify that the matching should be case insensitive. This is one of the options to the stringr regex() function.

Take our previous example,

x <- c("Cat", "CAT", "cAt") 
str_view(x, "cat")

To match the pattern cat in a case insensitive way, we wrap our pattern in regex() and specify the argument ignore_case = TRUE,

str_view(x, regex("cat", ignore_case = TRUE))

Notice that the matches retain their original case and any variant of cat matches.

Try it out to find the catcidents that involved tripping.

Instructions 1/2

undefined XP
    1
    2
  • First view the matches of catcidents to the pattern "TRIP". Notice how you only match those that are TRIP all in upper case.
  • Construct a case-insensitive regex to "TRIP" by calling regex() with ignore_case = TRUE. Assign the result to trip_pattern.
  • Repeat your viewing of catcident trips, this time using the case insensitive trip_pattern. You should get a few more hits.