On Mon, Sep 19, 2011 at 7:38 AM, Jer A <jeremy...@hotmail.com> wrote: > All, > > lets say i want to test if a string contains "pig" but not "dog" and/or not > "cat" > > i tried something like this: > > =~ m/[^dog]|[^cat]|pig/ig > > what is the best way of going about this, using one regex? > > your help is very much appreciated, > thanks. >
Hi Jeremy, I am not sure why would you want to use only one regex and IMHO it would be very complex to write that. It would make your code both unreadable and slow. I'd use two regexes for that: if ($str =~ m/pig/ and $str !~ /dog|cat/) { } Add the railing /i if you want this to be case insensitive. The /g is not needed as the first pig will be ok and the first dog or cat would also be indication that the match should fail. regards Gabor -- Gabor Szabo http://szabgab.com/ _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs