Tuesday, 15 June 2010

regex - Right gsub regexp entry -



regex - Right gsub regexp entry -

having string this:

"structure(list(a = 5, f = 6), .names = c(\"a\", \"f\"))"

where part

"structure(list( ), .names = c( ))"

always stays same. entries x=y within parentheses , theirs counterparts within c() changing both content y, label x, , count well.

what right global substitution, in sed or r gsub, result

"a = 5, f = 6"

using 1 gsub call? ie, before , after go away.

the intention r elipsis content "as is" 1 word , combine text in place in report. source comes "...".

one of solutions:

gsub("structure\\(list\\((.*)\\), .*$", "\\1", x) # [1] "a = 5, f = 6"

or equivalently:

gsub(".*list\\((.*)\\), .*$", "\\1", x)

regex r sed

No comments:

Post a Comment