Does anybody know how to negate a string in a grep command, i.e.,
what I need is to return only strings that do NOT contain a second
string anywhere in the entire string.
for
txt <-
c("boo","goo","doob","foo","boofoo")
I need a grep command that returns strings with "oo" except when
"b"
is present anywhere. I know that
grep("[^b]oo" would work to exclude "boo" and
"boofoo" but not "doob"
So, what I need is
grep("oo + some syntax", txt)
should return
goo doo foo
I have tried
grep("oo!boo",txt)
but it returns character(0).
any suggestions are much appreciated!
S.
--
Steven Orzack
You can try somthing about like this:
setdiff(txt, grep("(oob|boo|\\w[^oo]\\w)", txt, value = TRUE))
On Mon, Jun 22, 2009 at 6:45 PM, orzack <orzack@freshpond.org> wrote:
> Does anybody know how to negate a string in a grep command, i.e., what I
> need is to return only strings that do NOT contain a second string anywhere
> in the entire string.
>
>
> for
>
> txt <-
c("boo","goo","doob","foo","boofoo")
>
> I need a grep command that returns strings with "oo" except when
"b" is
> present anywhere. I know that
>
> grep("[^b]oo" would work to exclude "boo" and
"boofoo" but not "doob"
>
> So, what I need is
>
> grep("oo + some syntax", txt)
>
> should return
>
> goo doo foo
>
> I have tried
>
> grep("oo!boo",txt)
>
> but it returns character(0).
>
> any suggestions are much appreciated!
>
> S.
> --
> Steven Orzack
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
[[alternative HTML version deleted]]
Try txt[- grepl(pattern, txt)] txt[! grepl(pattern, txt)] On Mon, Jun 22, 2009 at 5:45 PM, orzack<orzack at freshpond.org> wrote:> Does anybody know how to negate a string in a grep command, i.e., what I > need is to return only strings that do NOT contain a second string anywhere > in the entire string. > > > for > > txt <- c("boo","goo","doob","foo","boofoo") > > I need a grep command that returns strings with "oo" except when "b" is > present anywhere. I know that > > grep("[^b]oo" would work to exclude "boo" and "boofoo" but not "doob" > > So, what I need is > > grep("oo + some syntax", txt) > > should return > > goo doo foo > > I have tried > > ?grep("oo!boo",txt) > > but it returns character(0). > > any suggestions are much appreciated! > > S. > -- > Steven Orzack > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Maybe Matching Threads
- calculate correlation effect size using contrast analysis for an omnibus Chi-square test statistic
- [LLVMdev] ubuntu on the mac
- [LLVMdev] [cfe-dev] Random, tiny question about doxygen comment style
- analysis of covariance and constrained parameters
- lmer and scale parameters....