如何使用R提取大字符串中的模式(开始和结束)?

如何使用R提取大字符串中的模式(开始和结束)?,r,regex,R,Regex,我有一个大字符串,我想用开始和结束搜索模式匹配/提取一个模式。如何在R中实现这一点 字符串的一个示例: big_stringstringr包非常适合这种类型的应用: library(stringr) big_string <- 'read.csv(\"http://company.com/students.csv\", header = TRUE)","solution":"# Preview students with str()\nstr(students)\n\n# Coerce G

我有一个大字符串,我想用开始和结束搜索模式匹配/提取一个模式。如何在R中实现这一点

字符串的一个示例:


big_stringstringr包非常适合这种类型的应用:

library(stringr)
big_string <- 'read.csv(\"http://company.com/students.csv\", header = TRUE)","solution":"# Preview students with str()\nstr(students)\n\n# Coerce Grades to character\nstudents$Grades <- read.csv(\"http://company.com/students_grades.csv\", header = TRUE)'

results<-unlist(str_extract_all(big_string, "http:.+csv"))
库(stringr)

你的问题不清楚。它是否总是要提取的URL?总是第一个和最后一个URL?始终使用引号?
http:.+?csv
也许更好我是Dave,刚刚测试了您的代码在示例中的实际工作情况。谢谢
big_string
的版本实际上比示例稍微复杂一点,并且由于某些原因,
http:.+/csv
起作用,而另一个则不起作用。