Skip to content
Prev 167431 / 398502 Next

regex -> negate a word

Wacek Kusnierczyk wrote:
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