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

incidentally, recent pcre accepts such regexes:

# r code
ungrep = function(pattern, x, ...)
    grep(paste(pattern, "(*COMMIT)(*FAIL)|(*ACCEPT)", sep=""), x,
perl=TRUE, ...)

strings = c("abc", "xyz")
pattern = "a[a-z]"
(filtered = strings[ungrep(pattern, strings)])
# "xyz"

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