我需要找到带有简单字符的重音字符。例如:加拿大法语中的“é”、“è”或带有 e 的“ê”,UTF-8。
library(tidyverse)
Sys.setlocale(locale = "fr_CA.UTF-8")
a <- c("Léger", "leger")
str_detect(a, regex("leger", ignore_case=T))
## [1] FALSE TRUE
str_detect(a, coll("leger", ignore_case=T, locale = "fra"))
## [1] FALSE TRUE
这段代码的结果应该是 TRUE,TRUE。
最佳答案
您可以将输入字符串转换为仅使用 ASCII 字符,然后对其进行匹配。例如
str_detect(iconv(a, to='ASCII//TRANSLIT'),regex("leger", ignore_case=T))
# [1] TRUE TRUE
关于r - 如何使用str_detect使用简单字符在R中查找法语UTF-8重音字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52007491/