in reply to Re: Match with line without a word
in thread Match with line without a word

There are a number of ways to do this. Easy way is with cascading "greps", like in my first example. Regex is wonderful at "or" but the "and" kind of thing can be complex in the syntax.

I would suggest one of the below formulations. Tweak to suit your needs.

oops, my brain is really out to lunch today...sorry.see update

#!/usr/bin/perl -w use strict; my @input = ("Exception : CEX", "Exception : TEX", "abc def ljj"); print grep{/TEX/} grep{/^\s*Exception/}@input; print "\n"; print grep{/Exception/ && /TEX/}@input; print "\n"; print grep{/^\s*Exception.*? TEX/}@input; __END__ prints: Exception : TEX Exception : TEX Exception : TEX
#!/usr/bin/perl -w use strict; my @input = ("Exception : CEX", "Exception : TEX", "abc def ljj"); print grep{!/CEX/}grep{/^\s*Exception/}@input; print "\n"; print grep{/Exception/ && !/CEX/}@input; print "\n"; __END__ prints: Exception : TEX Exception : TEX
I wouldn't get overly concerned about performance unless this code is going to be executed lots of times. Clarity should be the first priority.

Replies are listed 'Best First'.
Re^3: Match with line without a word
by Heaven (Initiate) on Aug 07, 2009 at 10:09 UTC
    Thanks a lot . I think this grep usage would do good , than nested regex .