r-使用regex启动with()



我想识别字符串是否以任何可能的字母开头,或者不以'#'开头。

为此,我尝试了:

example <- 'FN647863.1'  
startsWith(example, '[:alpha:]')

我本想得到TRUE,但不幸的是,我得到了FALSE

正如@Andrew所提到的,startsWith()不打算与一起使用regex。

那么工作解决方案是:

grepl("^[[:alpha:]]", example)

stringr对此也很好:

stringr::str_detect(example, "^[:alpha:]")

或对任何单词使用CCD_ 6。

最新更新