Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Regex to cange HTML %?? to char(0x??);

by Anonymous Monk
on Jun 20, 2001 at 00:18 UTC ( #89799=note: print w/replies, xml ) Need Help??


in reply to Regex to cange HTML %?? to char(0x??);

As they already said, there's a Module to do this ... or several (TMTOWTDI) ... but there's also a really cute expression that's worth grokking-in-fullness, even if you should use the module instead, since it's a lovely example of s///g and s///e together.

From Effective Perl Programming (Hall with Schwartz, 0-201-41975-0 not linked to Fatbrain, please support your local meatspace bookstore),

$_ = "a%5eb"; s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge;
which also says only one paragraph later
use URI::Escape; $_ = uri_unescape "a%5eb";
Both will result in $_ eq "a^b".

and Yes, it will handle "9%25EA" correctly, tranforming it to "9%EA" and not eating the output %. See s///g. (What's 9%EA? maybe fair share for 11-way split, less crumbs.)

-- Bill / n1vux

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2019-10-21 00:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?