Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Regex not working

by prasadbabu (Prior)
on Jul 17, 2009 at 09:40 UTC ( #780983=note: print w/replies, xml ) Need Help??

in reply to Regex not working

Hi Raghu,

As davorg suggested it is always better to use the HTML Parsers to do these kind of stuffs. You have missed 's' option modifier. Also use qr to quote regular expressions instead of manually backslashing everything.

use strict; use warnings; my $content = "<div class='roundedBoxBody'><p> <table>sample table</table> <p>&nbsp;</p></p>"; my $x = qr{<div class='roundedBoxBody'><p>}; my $y = qr{<p>&nbsp;</p></p>}; my $content_out = $1 if ($content =~ m|$x(.*)$y|s); print $content_out;


Replies are listed 'Best First'.
Re^2: Regex not working
by davorg (Chancellor) on Jul 17, 2009 at 09:44 UTC
    Also use qr to quote regular expressions instead of manually backslashing everything.

    That's actually not necessary here. The OP was just escaping things that didn't need escaping.

    $x = "<div class='roundedBoxBody'><p>"; $y = '<p>&nbsp;</p></p>';

    Works just as well.


    See the Copyright notice on my home node.

    Perl training courses

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://780983]
[erix]: s/dawn/dusk/
[erix]: (you're welcome :P)
[james28909]: you know, i had a thought a few mnths back. what if this universe were just a puzzle, waiting for life to figure it out!
[james28909]: what if one day we are able to grab the curtain that is "spacetime" and pull it back to reveal <insert imagination here> pulling at levers and ropes xD
[holli]: like dorothy?
[james28909]: see ya later holli
[james28909]: yeah like wizard of oz lol. its just a joke though
[james28909]: i cannot understand how someone cant see that a cloud of gas that evolves into a solar system or galaxies. it just makes sense to me. everythign that has happened, had to have happened for anything on this planet to be.
[james28909]: /gas/gas and debris/
[james28909]: another thing, i used to be atheist. life experiences, personal evidence. and my own perception is the reason why i believe the things i do.

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (13)
As of 2017-12-15 14:46 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (433 votes). Check out past polls.