str_匹配所有的换行符?
这将提取“此处”和“文本”之间的文本str_匹配所有的换行符?,r,regex,stringr,R,Regex,Stringr,这将提取“此处”和“文本”之间的文本 test <- "here is some text" str_match_all(test, "here(.*?)text") # [[1]] # [,1] [,2] # [1,] "here is some text" " is some " test可以使用空格字符选择选项“\\s”。此字符串“(.|\\s)”表示任何字符或空白 str_match_all(test, "here((.|\\s)*?)
test <- "here is some text"
str_match_all(test, "here(.*?)text")
# [[1]]
# [,1] [,2]
# [1,] "here is some text" " is some "
test可以使用空格字符选择选项“\\s”。此字符串“(.|\\s)”表示任何字符或空白
str_match_all(test, "here((.|\\s)*?)text")
[[1]]
[,1] [,2] [,3]
[1,] "here \nis \nsome \ntext" " \nis \nsome \n" "\n"
编辑
下面是另一个工作更好的表单(只有两个部分,但末尾还有一个额外的换行符):
可以使用空白字符选择选项“\\s”。此字符串“(.|\\s)”表示任何字符或空白
str_match_all(test, "here((.|\\s)*?)text")
[[1]]
[,1] [,2] [,3]
[1,] "here \nis \nsome \ntext" " \nis \nsome \n" "\n"
编辑
下面是另一个工作更好的表单(只有两个部分,但末尾还有一个额外的换行符):
不确定我们是否可以在r
中执行gs
,但这里显示python可以处理它。不确定我们是否可以在r
中执行gs
,但这里显示python可以处理它。这非常接近,但最后一个\n
是意外的?这非常接近,但最后一个\n
是意外的?