String split with conditions in R

后端 未结 7 1356
一向
一向 2021-02-04 00:05

I have this mystring with the delimiter _. The condition here is if there are two or more delimiters, I want to split at the second delimiter and if th

7条回答
  •  梦如初夏
    2021-02-04 01:01

    With the stringr package:

    str_extract(mystring, '.*?_.*?(?=_)|^.*?_.*(?=\\.ReCal)')
    [1] "MODY_60.2" "MODY_116.21" "MODY_116.3" "MODY_116.4"
    

    It also works with more than two delimiters.

提交回复
热议问题