Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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 rifling through the Monastery: (19)
As of 2015-07-28 18:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls