Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: extract a substring between two emements

by AnomalousMonk (Chancellor)
on Oct 10, 2011 at 14:32 UTC ( #930650=note: print w/replies, xml ) Need Help??


in reply to extract a substring between two emements

>perl -wMstrict -le "my $line = 'Hello hello START this is comment END ' . 'START this is still comment END ' . 'START this should still be comment END ' . 'this is fixed' ; ;; my $START = qr{ START \s* \K }xms; my $END = qr{ (?= \s* END) }xms; my $not_end = qr{ (?! $END) . }xms; ;; my ($extract) = $line =~ m{ $START $not_end* should $not_end* $END }xmsg; print qq{[[$line]]}; print qq{'$extract'}; " [[Hello hello START this is comment END START this is still comment END START this should still be comment END this is fixed]] 'this should still be comment'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://930650]
help
Chatterbox?
[LanX]: Wilkes left the computer field in 1972 to attend the Harvard Law School
[erix]: too many stubborn, illogical men in IT
LanX "We had the quaint notion at the time that software should be completely, absolutely free of bugs. Unfortunately it's a notion that never really quite caught on." :)
[LanX]: erix Silence, I sue you!
[erix]: She sounds like Dijkstra (you know, Edsger)
LanX will call his fifth son "Edsger"

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (13)
As of 2017-12-12 16:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (335 votes). Check out past polls.

    Notices?