hans glick hans glick - 1 year ago 62
R Question

R : everything that is not AND that is in one regular expression

x is a string :


I want to extract "white" in one regex in R
I try

gsub(pattern ="[(^[:alpha:])|(alt)]" ,replacement ="" ,x =x)

But obviously, it does not work. Any ideas?

Jan Jan
Answer Source

Is this what you're looking for?

some_vector <- c("alt=\"white\"/>", "alt=\"black\"/>")
colours <- gsub('(alt)="([^"]+)"', '\\1=""', some_vector)
# [1] "alt=\"\"/>" "alt=\"\"/>"

Generally, you should go for some parser instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download