Removing all “H” within the strings, EXCEPT the ones including “CH”

旧巷老猫 提交于 2019-12-12 17:05:46

问题


I am trying to remove all "H" within the strings, EXCEPT the ones including "CH" in the following example:

strings <- c("Cash","Wishes","Chain","Chip","Check")

I found that the code below remove only "H"

data<- gsub("H", "", strings)

回答1:


You can do this with a negative look-behind.

gsub("(?<!c)h", "", strings, perl=TRUE, ignore.case = TRUE)


来源:https://stackoverflow.com/questions/47538826/removing-all-h-within-the-strings-except-the-ones-including-ch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!