Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: RegEx Question - I want a line that contains this, but not this

by rubasov (Friar)
on Mar 30, 2010 at 18:29 UTC ( #831920=note: print w/replies, xml ) Need Help??


in reply to RegEx Question - I want a line that contains this, but not this

johngg's previous answer works perfectly, I only would like to show you a more general technic to express "I want my regex to match this, but do not match that". The key is to use a positive and a negative look-ahead together:
#! /usr/bin/perl use strict; use warnings; my $re_yummy = qr/^L[13]/; my $re_yucky = qr/TEXT/; while (<DATA>) { print if / \A (?= .* $re_yummy ) (?! .* $re_yucky ) /x; } __DATA__ L1 04:10:07.915 LOG: Want this Line1 L3 04:10:07.915 LOG: Want this Line2 L1 04:10:08.024 LOG: TEXT. Do not want this Line3 L3 06:37:58.163 LOG: TEXT. Do not want this Line4 L3 07:02:36.921 LOG: Want this Line5 L4 08:02:30.910 LOG: Do not want this Line6 L5 08:02:36.943 LOG: Do not want this Line7 L6 09:02:38.811 LOG: Do not want this Line8
  • Comment on Re: RegEx Question - I want a line that contains this, but not this
  • Download Code

Replies are listed 'Best First'.
Re^2: RegEx Question - I want a line that contains this, but not this
by Praveen_Noida_India (Initiate) on Mar 31, 2010 at 10:16 UTC
    Thats Good........

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://831920]
help
Chatterbox?
[choroba]: three
[choroba]: I mean I haven't used DBIx::Class nor M:S, only Moo
[1nickt]: Haha, I was learning about Linux filesystem trees trying to understand how Moo fits.
[1nickt]: I just got my feet wet with some DBIC coding this last week. I feel "meh" about it so far. It was pretty easy to add a sub to the DBIC class to filter search results ...
[1nickt]: ... in the calling code ... $rs = $rs->maturity(" stable");. But I don;t enjoy feeling that far away from the SQL and the DB, really.
[1nickt]: The same project (CPAN Testers API) is using experimental signatures (and therefore 5.024) ... which is what replaced Method::Signatures , afaict.
[1nickt]: But the new $job is on an older Perl and therefore using M::S, the syntax of which looks clunky to me, so far.

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2017-11-24 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (349 votes). Check out past polls.

    Notices?