سؤال

I'm working in R and having troubles escaping the backslash. I am using the library stringr.

install.packages("stringr", repos='http://cran.us.r-project.org')
library("stringr")

I would like to do str = str_replace_all(str, "\", "")

So I tried str = str_replace_all(str, "\\", "") but it won't work.

What should I do?

هل كانت مفيدة؟

المحلول

I found a solution that works

str = gsub("([\\])","", str)

نصائح أخرى

Use Hmisc::escapeRegex and Hmisc::escapeBS which automatically escapes backslashes and other regex special characters.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top