I am trying to remove the words "Arts and Humanities" and "Social Sciences" from a string containing concatenated by "/" different disciplines of knowledge as follows:
string = "Arts and Humanities Other Topics/Social Sciences Other Topics/Arts and Humanities/Social Sciences/Sociology"
I have tried this using stringr
package:
sapply(strsplit(string, "/"), function(x) paste(str_remove(x, "\\bArts and Humanities\\b|\\bSocial Sciences\\b"), collapse = "/"))
But the output generated is " Other Topics/ Other Topics///Sociology"
and I need an output like this:
"Arts and Humanities Other Topics/Social Sciences Other Topics/Sociology"
Thanks in advance.