Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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;

Prasad


Comment on Re: Regex not working
Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://780983]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (15)
As of 2014-07-30 13:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (232 votes), past polls