Skip to content
Prev 198843 / 398503 Next

partial matching with grep()

On Nov 2, 2009, at 9:57 AM, Vito Muggeo (UniPa) wrote:

            
> grep("\\.x\\b",c("a.x" ,"b.x","a.xx"),value=TRUE)
[1] "a.x" "b.x"

Or:
 > grep("\\.x$",c("a.x" ,"b.x","a.xx"),value=TRUE)
[1] "a.x" "b.x"

Why you might ask. You need the double "\\" in order to get the  
interpreter to interpret them as single escapes prior to the period  
and the "\" in "\b", which is the end-of-word match pattern, while "$"  
is an end of sentence pattern.
David Winsemius, MD
Heritage Laboratories
West Hartford, CT