Reputation: 107
I had a table of data looks as following:
| _ - 9 | PR - Very happy with results. | Improvement - Be more clear regarding how the entire process works. I.e. how long you have to wait for your account to become active. | Churn Reason - none"
I try to delete | Improvement...|
from each row if there is one. I wrote the it as
feedback <- gsub("| Improvement*|", "",data$Feedback, ignore.case = FALSE, perl = TRUE)
But it does nothing. Is anyone can help me with this?
Upvotes: 2
Views: 750
Reputation: 75649
You need to escape the pipe characters |
, because they are interpreted as OR. You also need a .
for the *
quantifier to apply to. Finally, although it does not matter for this example, you probably want the non-greedy version of *
so that you don't collect more than one field worth of stuff.
Feedback = "| _ - 9 | PR - Very happy with results. | Improvement - Be more clear regarding how the entire process works. I.e. how long you have to wait for your account to become active. | Churn Reason - none"
feedback <- gsub("\\| Improvement.*?\\|", "", Feedback, ignore.case = FALSE, perl = TRUE)
print(feedback)
Output:
"| _ - 9 | PR - Very happy with results. Churn Reason - none"
Upvotes: 2