regex -> negate a word
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