Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
str_匹配所有的换行符?_R_Regex_Stringr - Fatal编程技术网

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
是意外的?