str_replace_all 不适用于 R 中的“\n+”

str_replace_all not working for "\n+" in R

我有一些变量值想用 str_replace 和 str_replace_all 更新。我很想知道为什么当“\n”是字符模式的一部分时这些函数不起作用,例如“\n+\n”。

str_replace( "Example\nof\n+\nmy\nProblem", "\n+\n", "")

我想要这样来制作 "Example\nofmy\nProblem"。

您需要在加号前加上\\。例如:

str_replace( "Example\nof\n+\nmy\nProblem", "\n\+\n", "")