R 非英语字符的正则表达式
我需要检查一些字符串是否包含任何非英语字符R 非英语字符的正则表达式,r,regex,special-characters,R,Regex,Special Characters,我需要检查一些字符串是否包含任何非英语字符 x = c('Kält', 'normal', 'normal with, punctuation ~-+!', 'normal with number 1234') grep(pattern = ??, x) # Expected output:1 您可以使用PCRE正则表达式: x = c('Kält', 'normal', 'normal with, punctuation ~-+!', 'normal with number 1234')
x = c('Kält', 'normal', 'normal with, punctuation ~-+!', 'normal with number 1234')
grep(pattern = ??, x) # Expected output:1
您可以使用PCRE正则表达式:
x = c('Kält', 'normal', 'normal with, punctuation ~-+!', 'normal with number 1234')
grep(pattern = "[^[:ascii:]]", x, perl=TRUE)
grep(pattern = "[^[:ascii:]]", x, value=TRUE, perl=TRUE)
输出:
[1] 1
[1] "Kält"
请参见按预期工作!谢谢Wiktor!