detect non ascii characters in a string

前端 未结 4 1801
暗喜
暗喜 2020-12-09 08:24

How can I detect non-ascii characters in a vector f strings in a grep like fashion. For example below I\'d like to return c(1, 3) or c(TRUE, FALSE, TRUE,

4条回答
  •  情书的邮戳
    2020-12-09 09:17

    Came across this later using pure base regex and so simple:

    grepl("[^ -~]", x)
    ## [1]  TRUE FALSE  TRUE FALSE
    

    More here: http://www.catonmat.net/blog/my-favorite-regex/

提交回复
热议问题