Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: encode HTML entities with a regexp

by Ido (Hermit)
on May 12, 2005 at 16:40 UTC ( [id://456469]=note: print w/replies, xml ) Need Help??


in reply to Re: encode HTML entities with a regexp
in thread encode HTML entities with a regexp

I believe this might be a little buggy, unless I misunderstand the requirement. But take a look at:
use strict; my $input=' This is sample &lt;This is sample text> This is sample &lt;Th<a> </a>is is sa<not a>mple text <a>this is samp +le text</a> sample text >'; my @arr=$input=~m#&lt;[^<>]+(?:<a>.+?</a>[^<>]*)?>#g; print join "\n",@arr;
I'm wondering about what might be inside <a>..</a>, and whether they should be balanced. In case not, you could simply go for:
qr {&lt;(?:[^<>]+|<a>|</a>)*>}

Or perhaps:
qr {&lt;(?:[^<>]+|<a>|</a>)*[^>]*>}
Otherwise, you might try:
my $re; $re=qr{(?:[^<>]+|<a>(??{$re})?</a>)*}; my @arr=$input=~m#&lt;$re>#g;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-24 04:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found