Reputation: 1538
Is there a more elegant way to find out which elements of a character string vector end with a colon, period or bracket? (Also, I might later want to include question marks etc.)
x <- c("2)", "This", "is", "a", "Test:", "Find", "the", "dots.", "Which", "ones")
which(grepl("\\.$", x) | grepl("\\:$", x) | grepl("\\)$", x))
Upvotes: 0
Views: 842
Reputation: 1538
Thanks, nrussell and docendo discimus.
grep("[.:)]$", x)
Upvotes: 2