Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 非英语字符的正则表达式_R_Regex_Special Characters - Fatal编程技术网

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!