How to extract everything until first occurrence of pattern

前端 未结 4 1691
夕颜
夕颜 2021-02-19 00:22

I\'m trying to use the stringr package in R to extract everything from a string up until the first occurrence of an underscore.

What I\'ve tried

4条回答
  •  太阳男子
    2021-02-19 00:46

    The regex lookaround should be

    str_extract("L0_123_abc", ".+?(?=_)")
    #[1] "L0"
    

提交回复
热议问题