R-regex: match strings not beginning with a pattern

后端 未结 3 538
谎友^
谎友^ 2020-12-29 06:43

I\'d like to use regex to see if a string does not begin with a certain pattern. While I can use: [^ to blacklist certain characters, I can\'t figure out how to

3条回答
  •  长情又很酷
    2020-12-29 06:47

    There is now (years later) another possibility with the stringr package.

    library(stringr)
    
    str_detect("dsadsf", "^abc", negate = TRUE)
    #> [1] TRUE
    
    str_detect("abcff", "^abc", negate = TRUE)
    #> [1] FALSE
    

    Created on 2020-01-13 by the reprex package (v0.3.0)

提交回复
热议问题