Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: pattern matching (greedy, non-greedy,...)

by Skeeve (Vicar)
on Dec 17, 2009 at 09:57 UTC ( #813163=note: print w/ replies, xml ) Need Help??


in reply to pattern matching (greedy, non-greedy,...)

I managed to use the range operator for this:

#!/bin/env perl use strict; use warnings; my $start= qr/^KEY$/; my $end = qr/^PATTERN$/; my $match; while (<DATA>) { if (my $hit= /$start/ .. /$end/) { $match= '' if /$start/; $match.= $_; print $match if $hit ne 0+$hit; } } __DATA__ KEY blah blahblah KEY blah ah other random stuff KEY blah ha other random stuff PATTERN asdf KEY fdas PATTERN

I simply reset my buffer when I find the start a second time.


s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e


Comment on Re: pattern matching (greedy, non-greedy,...)
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2014-12-22 14:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (119 votes), past polls