Message-ID: <49739CB4.5080303@idi.ntnu.no>
Date: 2009-01-18T21:18:44Z
From: Wacek Kusnierczyk
Subject: regex -> negate a word
In-Reply-To: <4973995A.7040305@idi.ntnu.no>
Wacek Kusnierczyk wrote:
>
> # r code
> ungrep = function(pattern, x, ...)
> grep(paste(pattern, "(*COMMIT)(*FAIL)|(*ACCEPT)", sep=""), x,
> perl=TRUE, ...)
>
> strings = c("abc", "xyz")
> pattern = "a[a-z]"
> (filtered = strings[ungrep(pattern, strings)])
> # "xyz"
>
this was a toy example, but if you need this sort of ungrep with
patterns involving alterations, you need a fix:
ungrep("a|x", strings, value=TRUE)
# "abc"
# NOT character(0)
# fix
ungrep = function(pattern, x, ...)
grep(paste("(?:", pattern, ")(*COMMIT)(*FAIL)|(*ACCEPT)", sep=""),
x, perl=TRUE, ...)
ungrep("a|x", strings, value=TRUE)
# character(0)
vQ