x is a string :
x="alt=\"white\"/>"
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?
x is a string :
x="alt=\"white\"/>"
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?
Is this what you're looking for?
some_vector <- c("alt=\"white\"/>", "alt=\"black\"/>")
colours <- gsub('(alt)="([^"]+)"', '\\1=""', some_vector)
colours
# [1] "alt=\"\"/>" "alt=\"\"/>"
Generally, you should go for some parser instead.
Try this if you are interested in some pattern appearing within the quotes only:
gsub(".*\"(.*)\".*", "\\1", x)
#[1] "white"