Extract text using regex in R

后端 未结 5 1936
一整个雨季
一整个雨季 2021-01-25 02:15

I read the text file with below data and am trying to convert it to a dataframe

Id:   1
ASIN: 0827229534
  title: Patterns of Preaching: A Sermon Sampler
  group         


        
5条回答
  •  走了就别回头了
    2021-01-25 02:46

    EDIT: Correcting my answer.

    Using stringr:

    library(stringr)
    
    ids <- str_extract(text, 'Id:[ ]*\\S+')
    ASIN <- str_extract(text, 'ASIN:[ ]*\\S+')
    title <- str_extract(text, 'title:[ ]*\\S+')
    group <- str_extract(text, 'group:[ ]*\\S+')
    similar <- str_extract(text, 'similar:[ ]*\\S+')
    rating <- str_extract(text, 'avg rating:[ ]*\\S+')
    

提交回复
热议问题