Learn R Programming

cwhmisc (version 5.0)

grepnot: Grep utility

Description

Show elements passing or not a grep.

Usage

grepnot(s,x,value=TRUE)

Arguments

s,x
String
value
Boolean

Details

s String regular expression, see link{grep}. x Array of strings to check with grep. value Third argument to grep proper.

Examples

Run this code
x <- c("Ab","d","#12","",".1", "m.","",  "$y")
y <- c(".x", ".","c.",  "$y", "_p","12")
grepnot("^A[[:alpha:]]+",x) #  "Ab"  "\"  " d"  "#12" "  "  ".1"  "m."  ""    "$y"
grepnot("A[[:alpha:]]+",x)  #  "Ab"  "\"  " d"  "#12" "  "  ".1"  "m."  ""    "$y"
grepnot("a[[:alpha:]]+",x) # "\" ...
grepnot("#[[:alnum:]]+",x) #  "#12" "\" ...
grepnot("$",x) #  ""    "\" ...
grepnot("[^$][[:alnum:]].]+",x) # "\" ...
grepnot("[^[$]][[:alnum:]].]+",x) # "\" ...
# grepnot("[^\$][[:alnum:]].]+",y) # "\" ...
grepnot("^[$][[\s]]+",x) # '\s' is an unrecognized escape
grepnot("^.[[:alpha:]]+",x,FALSE) # "1"   "2"   "\" "3"   "4"   "5"   "6"   "7" 
grepnot("^.[[:alpha:]]+",x) # "Ab"  " d"  "\" "#12" "  "  ".1"  "m."  "" 

grepnot("^\.[[:alpha:]]+",x) # "1"   "2"   "\" "3"   "4"   "5"   "6"   "7" 
grepnot("^\.[[:alpha:]]+",y) # 
grepnot("^\$[[:alpha:]]+",y)
grepnot("^_[[:alpha:]]+",y)
grepnot("^[^\.][[:alpha:].]+",y) #[1] " ."  "c."  "$y"  "_p"  "\" ".x"  "12"

Run the code above in your browser using DataLab