I am having problems with this regex. Consider the following vector.
> vec <- c("new jersey", "south dakota", "virginia:chincoteague",
"washington:whidbey island", "new york:main")
Of those lines that contain :, I would like to leave only mainafter :, as a result of which
[1] "new jersey" "south dakota" "new york:main"
So far, I managed to get there with this ugly enclosed nightmare, which, of course, is far from optimal.
> g1 <- grep(":", vec)
> vec[ -g1[grep("main", grep(":", vec, value = TRUE), invert = TRUE)] ]
How can I write one regex to save :main, but delete others containing :?
source
share