Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by dimmesdale (Friar)
on Jun 19, 2001 at 21:54 UTC ( #89754=note: print w/replies, xml ) Need Help??


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

Well, here's a solution, but there's a module that does this--I just can't think of it now. Give CPAN a good look, and someone will probably respond with it. Here's the solution:
$str =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr(hex($1))/eg;

Replies are listed 'Best First'.
Re: Re: Regex to cange HTML %?? to char(0x??);
by TGI (Parson) on Jun 19, 2001 at 23:56 UTC

    How about these?

    # The above shrunk a bit. $str =~ s/%([0-9A-F][0-9A-F])/chr(hex($1))/ieg; # - or more cryptic $str =~ s/%([0-9A-F][0-9A-F])/sprintf("%1c",hex($1))/ieg;

    Can anyone think of something that doesn't use hex?


    TGI says moo

    Update

    Bill's post and Abigail's clever method taken together let us chop off another character or so:

    s/%([0-9A-F]{2})/"chr 0x$1"/igee;

    TGI - Syncretic Cretin

      Can anyone think of something that doesn't use hex?
      s/%([0-9A-F][0-9A-F])/"chr 0x$1"/ieeg;

      -- Abigail

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2019-09-18 04:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (222 votes). Check out past polls.

    Notices?