Hi, I was trying to find a pattern ("ABHD14A") in a character string ('xgen' in example below) using grepl. Note that the individual members may be separated by a semi-colon.
The correct answer should return: "ABHD-ACY1 ; ABHD14A" "ABHD14A ; YYY" I have tried three approaches, but still seem a bit off. Attempt 2 below gets closest, but it also returns a hit where my pattern is a substring. Here is my code: =========== xgen <- c("XYZ","ABHD-ACY1 ; ABHD14A","ABHD14AXX","ABHD14A ; YYY") ga <- "ABHD14A" # 1. kx <- grepl(paste0("^",ga,"$"),xgen) xgen[kx] # 2. ky <- grepl(ga,xgen) xgen[ky] ============== What do I need to add/change in #2 above? many thanks! [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.