เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

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.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

String Manipulation with stringr in R

ดูคอร์ส

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# View matches to "TRIP"
___

# Construct case insensitive pattern
trip_pattern <- ___

# View case insensitive matches to "TRIP"
___
แก้ไขและรันโค้ด