Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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 (Canon) 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?
Discipulus yaaawn..
[Corion]: DST does that to everybody...
Corion attempts to find who to address to better target his drive-by patches
[Corion]: This time it's for the Duktape embedded Javascript engine, which would be nice to have IMO, but doesn't compile on Windows currently

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2017-03-27 11:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (319 votes). Check out past polls.