非英语字符的正则表达式

Dee*_*ena 4 regex r special-characters

我需要检查一些字符串是否包含任何非英文字符.

x = c('Kält', 'normal', 'normal with, punctuation ~-+!', 'normal with number 1234')
grep(pattern = ??, x) # Expected output:1
Run Code Online (Sandbox Code Playgroud)

Wik*_*żew 5

您可以使用[^[:ascii:]]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) 
Run Code Online (Sandbox Code Playgroud)

输出继电器:

[1] 1
[1] "Kält"
Run Code Online (Sandbox Code Playgroud)

参见R演示