Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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]
[Eily]: The best example of that is the TGV, they couldn't decide who would get it so it's in the middle of nowhere halfway between the two
[LanX]: Eily: that rings a bell
[erix]: interesting difference, I suppose they use different data/routes (and shorter seems better, no?)
[LanX]: Montabaur station
[erix]: (I used http://afstandmete )
LanX The stations of Limburg Süd and Montabaur, which are approximately 20 km apart, ...
[LanX]: teh route I get from gmaps is 1662 km long and is crossing the Swiss Alps (mounting 2400 m) ... I wouldn't try this in December...

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

    Results (369 votes). Check out past polls.