Extract text between certain symbols using Regular Expression in R

后端 未结 5 1314
刺人心
刺人心 2020-12-05 20:35

I have a series of expressions such as:

\"the text I need to extract
\"

I need to extrac

5条回答
  •  醉酒成梦
    2020-12-05 21:35

    You can use the following approach with gregexpr and regmatches if you don't know the number of matches in a string.

    vec <- c("the text I need to extract
    ", "abc another text def and another text ghi") regmatches(vec, gregexpr("(?<=).*?(?=)", vec, perl = TRUE)) # [[1]] # [1] "the text I need to extract" # # [[2]] # [1] "another text" "and another text"

提交回复
热议问题