Skip to content
Prev 374693 / 398503 Next

removing part of a string

Hello,

Try this.


ss1 <- "z:f(5, a=3, b=4, c='1:4', d=2)"
ss2 <- "f(5, a=3, b=4, c=\"1:4\", d=2)*z"

fun <- function(s) sub("(\\().*(\\))", "\\1\\2", s)

fun(ss1)
#[1] "z:f()"

fun(ss2)
#[1] "f()*z"


Hope this helps,

Rui Barradas
On 5/21/2018 2:33 PM, Vito M. R. Muggeo wrote: