str_remove到多行字符串的末尾

时间:2018-12-03 10:05:44

标签: r stringr

如何将纵梁移除到多行文档的末尾?

require(stringr)
x = 'The quick brown
fox jumps over
the lazy dog'

str_remove(x, regex('jumps.*', multiline = TRUE)) %>% cat
#> The quick brown
#> fox 
#> the lazy dog

1 个答案:

答案 0 :(得分:1)

该解决方案如何?

library(stringr)
library(dplyr)

x = 'The quick brown
fox jumps over
the lazy dog'

str_replace(x, regex('jumps.*\n*.*'), "") %>% cat

应与:

str_remove(x, regex('jumps.*\n*.*')) %>% cat