HI I want to replace a forward slash by a space, but only if it appears once.
str_replace_all( 'NOOOOO//ABCDEFGHI/asdfasd//sdkksksks', "/(?!=/)", " ")
Here I want the output to be: NOOOOO//ABCDEFGHI asdfasd//sdkksksks
Try the following option with sub:
input <- "NOOOOO//ABCDEFGHI/asdfasd//sdkksksks"
gsub("(?<!/)/(?!/)", " ", input, perl=TRUE)
[1] "NOOOOO//ABCDEFGHI asdfasd//sdkksksks"
The strategy here is to use the pattern (?<!/)/(?!/), which matches a single forward slash which it surrounded on both sides by anything other than another forward slash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With