search for: grepcut

Displaying 1 result from an estimated 1 matches for "grepcut".

2011 Jun 05
1
Negating two identical characters with regular expressions
Hello all, Let's say I have a character string "Race-ethnicity-----coding information" I want to extract all text before the multiple dashes, including the word "ethnicity." I wrote a handy function to extract the first matched text: grepcut <- function(pattern,x){ start.and.length <- regexpr(pattern,x) substring(x,start.and.length,start.and.length +attr(start.and.length,"match.length")-1)} grepcut("^[^-]+","Race-ethnicity-----coding information") The above grepcut, of course, returns only the stri...