[英]R case insensitive capturing group
這個正則表達式:
str_extract_all("This is a Test , ' ' " , "[a-z]+")
返回:
[1] "his" "is" "a" "est"
如何修改以使其不區分大小寫?
`[1] "This" "is" "a" "Test"`
應該返回
/i
是否應該區分大小寫?
嘗試str_extract_all("This is a Test , ' ' " , "[az]+/i")
回報
[[1]]
character(0)
字符串函數有一個特殊的表示法:
regex(pattern, ignore_case = FALSE, multiline = FALSE, comments = FALSE, dotall = FALSE, ...)
您可以使用
> str_extract_all("This is a Test , ' ' " , regex("[a-z]+", ignore_case=TRUE))
[[1]]
[1] "This" "is" "a" "Test"
或者,使用內聯i
修飾符(?i)
:
str_extract_all("This is a Test , ' ' " , "(?i)[a-z]+")
您可以嘗試將大寫字母包括在要搜索的集合中。
str_extract_all("This is a Test , ' ' " , "[A-Za-z]+")
如果您只希望首字母大寫,則可以嘗試以下代碼。 它使第一個字母不區分大小寫,然后只包含小寫字母。
str_extract_all("This is a Test , ' ' " , "[A-Za-z][a-z]*")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.