[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [Regexp] a regexp question
From: |
jon |
Subject: |
RE: [Regexp] a regexp question |
Date: |
Fri, 7 May 2004 11:32:12 -0700 |
I think you'll keep your sanity if you just double process. Just because you
*can* get it all in one pattern doesn't mean it's efficient or maintainable.
But, here's an example of doing what you want in Perl:
#!/usr/bin/perl
@testData = (
'my kitty is very cute',
'but puppy is cuter than kitty',
);
foreach (@testData) {
if (/^(?!.*puppy).*kitty/) {
print "This matches: $_\n";
}
else {
print "This does not match: $_\n";
}
}
Later
> -----Original Message-----
> From: address@hidden
> [mailto:address@hidden Behalf Of
> Hartwig, Thomas
> Sent: Friday, May 07, 2004 11:15 AM
> To: address@hidden
> Subject: Re: [Regexp] a regexp question
>
>
> Sorry for not having a solution, except double processing the strings.
> Some years ago I found a regexp definition where strings could be
> defined as parts of a character class something for your problem would
> look like that: ^[^[:puppy:]]*kitty
>
> But I can't remember where it was. However, I have your problem like you
> sometimes as well, but rewrite it with some kind of double processing.
> The manpage of perlre contains a solution for that as well. Look for
> "Extended Patterns"
>
> Finaly I wanted to affirm your problem and say that I'm interested in a
> standard solution as well.
>
> Who knows about that?
>
> Cheers
> Thomas
>
> Levent Yilmaz wrote:
> > Hello,
> >
> > It sounded like a very simple problem but I couldn't come up with a
> > solution. I was trying to do this with Basic Regexp in grep:
> >
> > Find all lines which contain the word 'kitty'. But only those
> lines that
> > do not have 'puppy' somewhere before 'kitty'. For instance:
> >
> > my kitty is very cute
> > but puppy is cuter than kitty
> >
> > What regular expression stands for the first line but not the second?
> > Note that the other way is very easy, that is the lines with 'puppy'
> > followed by 'kitty': puppy.*kitty
> >
> > thank you so very much!
> > -Levent.
> >
> >
> > PS: What is all this spam on the list by the way?
> >
> >
> >
> > _______________________________________________
> > Gnu-regexp-users mailing list
> > address@hidden
> > http://mail.gnu.org/mailman/listinfo/gnu-regexp-users
>
> --
> Thomas Hartwig - Software & IT-Service Specialist
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.677 / Virus Database: 439 - Release Date: 5/4/2004
>