Gabor Grothendieck wrote:
> Try this:
>
> grep("^([^a]|a[^b]|ab[^c])*.{0,2}$", x, perl = TRUE)
>
>   
... and see how cumbersome it becomes for a pattern as trivial as 'abc'. 

in perl, you typically don't invent such negative patterns, but rather
"don't match" positive patterns: instead of the match operator =~ and a
negative pattern, you use the no-match operator !~ and a positive pattern:

@strings = ("abc", "xyz");
@filtered = grep $_ !~ /abc/, @strings;

in r, one way to do the no-match is using -grep, but taking care of the
special case of no matches at all in the input vector.


> On Sun, Jan 18, 2009 at 2:37 PM, Rau, Roland <r...@demogr.mpg.de> wrote:
>   
>> Thank you very much to all of you for your fast and excellent help.
>> Since the "-grep(...)" solution seems to be favored by most of the answers,
>> I just wonder if there is really no regular expression which does the job?!?
>>     

in perl 5.10, you can try this:

@strings = ("abc", "xyz");
@filtered = grep $_ =~ /(abc)(*COMMIT)(*FAIL)|(*ACCEPT)/, @strings;

which works by making a string that matches the pattern fail, and any
other string succeed despite no match.

vQ

______________________________________________
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.

Reply via email to