I need to use grep
to find all strings ending with G
but NOT ending with STIG
or VÄG
in the following character vector:
test=c("EWASPG","AVOPW","SDAGSTIG","ASDVVÄG","ASDVWE","QSCIUVG","QWSFNJG")
I tried this but it returns false for any string with the letters S
, T
, I
, V
, Ä
preceding the G
instead of returning false when the G
is preceded by the exact phrase.
grep("[^((STI)|(VÄ))]G$", test, value=T)
# [1] "EWASPG" "QWSFNJG"
Thanks!
I am aware of this post.