Replace Text between : and , to "X"

Input :

My name : Harry, Age : 23, Address : London,

Need the output string to be :

My name : X, Age : X, Address : X,

This can be done with str_replace_all from the stringr package.

S <- "My name : Harry, Age : 23, Address : London,"
library(stringr)
str_replace_all(S, ":[^,]+,", ": X,")
#> [1] "My name : X, Age : X, Address : X,"

Created on 2019-06-25 by the reprex package (v0.2.1)

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.