Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

extract a substring between two emements

by Shaveta_Chawla (Sexton)
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

Replies are listed 'Best First'.
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 exilepanda (Pilgrim) 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 AnomalousMonk (Chancellor) 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?
[Corion]: Oh yay. The (external, not guided by me) programmers have chosen Moose+DBIx::Class for some implementation, and now seem to do 1+n SELECT statements for each row, as is usual when using ORMs.
[Corion]: So maybe I should investigate how to plug in a cache in front of DBIx::Class so I can do a ->selectall_hashre f and then satisfy the "sub"-selects from that cached single SELECT statement ...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2017-09-25 10:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (279 votes). Check out past polls.

    Notices?