Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Think about Loose Coupling
 
PerlMonks  

extract a substring between two emements

by Shaveta_Chawla (Acolyte)
on Oct 10, 2011 at 06:36 UTC ( #930538=perlquestion: print w/ replies, xml ) Need Help??
Shaveta_Chawla has asked for the wisdom of the Perl Monks concerning the following question:

i want to extract a string from a line. The line is::

$line = 'Hello hello start this is comment end start this is still comment end start this should still be comment end this is fixed';
$line = 'Hello hello start this is still comment end start this should still be comment end this is fixed';
$line = 'Hello hello start this should still be comment end this is fixed';

i need to extract "this should still be comment" from the lines using one regular expression.

Comment on extract a substring between two emements
Re: extract a substring between two emements
by exilepanda (Monk) on Oct 10, 2011 at 07:00 UTC
    $line =~ m/href="([^"]+.pdf)"/i;

    Is that what you want ?

      Please read my question again as i have changed it and please reply according to that.
        When changing your question, you should keep the original content (you can use striking and underlining to mark deleted and inserted text), so older replies do not become nonsense.
Re: extract a substring between two emements
by Anonymous Monk on Oct 10, 2011 at 07:04 UTC
Re: extract a substring between two emements
by AnomalousMonk (Monsignor) on Oct 10, 2011 at 14:32 UTC
    >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: perlquestion [id://930538]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-04-17 23:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (459 votes), past polls