s <- "a-b-c-d" # sub replaces only the first match print(sub("-", "_", s)) # gsub replaces every match print(gsub("-", "_", s))
replace matches