Capturing parts of string using regular expression in R

前端 未结 3 1852
盖世英雄少女心
盖世英雄少女心 2021-01-21 19:01

I have these strings:

myseq <- c(\"ALM_GSK_LN_06.ID\",\"AS04_LV_06.ID.png\",\"AS04_SP_06.IP.png\")

What I want to do is to capture parts of

3条回答
  •  太阳男子
    2021-01-21 19:32

    Totally stealing @hwnd's regex but in a tidyr/dplyr approach:

    library(dplyr); library(tidyr)
    data_frame(myseq) %>%
        extract(myseq, c('A', 'B', 'C'), '(.+)_([A-Z]+)[^.]+\\.([A-Z]+)')
    
    ##         A  B  C
    ## 1 ALM_GSK LN ID
    ## 2    AS04 LV ID
    ## 3    AS04 SP IP
    

提交回复
热议问题