Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Another Look behind

by dominic01 (Sexton)
on Mar 13, 2015 at 16:54 UTC ( [id://1119976]=note: print w/replies, xml ) Need Help??


in reply to Re: Another Look behind
in thread Another Look behind

First your solution works perfectly for me. Next your are right that the some of my "capturing" doesnt make any sense and I was just testing few things by capturing it.

Next I dont understand how to use the negative variable width look-back with (*SKIP)(*FAIL) when I have a huge regex. For e.g.

$Line =~ /^(Some_RegEx) (Some_RegEx) (Some_RegEx)(?<!foo.*|some text) +$Jrnl (Some_RegEx)$/;
Appreciate any pointers in this regard.

Replies are listed 'Best First'.
Re^3: Another Look behind
by AnomalousMonk (Archbishop) on Mar 13, 2015 at 21:16 UTC

    I don't have a good idea of your difficulties, but here's a generalized approach. I can't provide a working example at the moment, so the following is untested handwaving.

    The  (*SKIP)(*FAIL) variable-width negative look-back hack works by messing up a match of something you need to have for an overall match. For a large regex, I tend to take the approach of factoring regex elements:

    # stuff we want to capture my $capture_this = qr{ ... }xms; my $capture_too = qr{ ... }xms; my $capture_also = qr{ ... }xms; my $capture_more = qr{ ... }xms; # stuff we want to cause match failure if before certain other stuff my $avoid_this = qr{ ... }xms; my $avoid_too = qr{ ... }xms; my $avoid_also = qr{ ... }xms; my $negatory = qr{ (?> [aeiou]+ | f[eio]e? | $avoid_too) }xms; # stuff we need for an overall match, may or may not be captured my $needed_for_match = qr{ ... }xms; my $needed_too = qr{ ... }xms; my $string = get_stringy_stuff(); my ($this, $too, $also, $yet_another) = $string =~ m{ \A ($capture_this) ($capture_too) ... (?> (?> $avoid_this | $avoid_too | $avoid_also | etc) $needed_for_ +match (*SKIP)(*F))? $needed_for_match # needed for overall match ($capture_also) ... (?> $negatory $needed_too (*SKIP)(*FAIL))? ($needed_too) # needed for overall match, also captured \z }xms; do_something_with($this, $too, $also, $yet_another);


    Give a man a fish:  <%-(-(-(-<

      This is perfect explanation. Thank you very much.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1119976]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-03-28 08:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found