我想在R中删除下一行以空格或制表符开头的换行符。
text <- gsub("\n(?=\\h)","",x,perl=True)
但没有成功
您可以使用
text <- gsub("\\R(?=\\h)", "", x, perl=TRUE)
该 \R(?=\h)
模式匹配任何换行序列(用 \R
)之前的任何水平空白处(用 (?=\h)
正面看)。)
见一个 R演示:
x <- "Line 1\r\n coninuation of line 1\r\nLine 2"
gsub("\\R(?=\\h)", "", x, perl=TRUE)
## => [1] "Line 1 coninuation of line 1\r\nLine 2"
我们可以使用 TRUE
而不是 True
在 R
gsub("\n(?=\\h)","",x,perl=TRUE)