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

Re: Control Characters (\xNN) in HTML

by scain (Curate)
on Oct 18, 2001 at 20:42 UTC ( [id://119733]=note: print w/replies, xml ) Need Help??


in reply to Control Characters (\xNN) in HTML

The reason your substitution isn't working is because you aren't escaping the first backslash \x probably has a special meaning and even if it doesn't \x means x (backslashed \> for example means >).

To fix the regex, rewrite it like this:

s/\\x(\d+)/'&#' . hex($1) . ';'/ge
The \d+ will work as you think it should (that is, as you wrote it).

Scott

Update: I should have guessed, but the \x followed by a two digit hex number means to look for a hex number, which is probably what confused you in the first place: you are looking for the text representation of a hex number (ie, \x92) which is plain text, not the hex number itself.

The Real Update: OK, you said For instance, the single character \x92; scain, read the problem (or as my High School Chemistry teacher wrote RTGDP). \x followed by digits matches a hex nubmer. What I don't know is how to get it to match a range of numbers. You might try several things, like [\x90-\xFF], which if Perl DWIM, would mean to match any hex number in that range. Also, since \x actually matches the number, what you really want to capture is the whole thing; so assuming the range works as I have written it, rewrite the regex like this:

s/([\x90-\xFF])/'&#' . $1 . ';'/g
I am really fuzzy on whether that will work, but don't have an easy way to test it; let me know. Note that this way, you no longer need the e at the end of the regex.

Log In?
Username:
Password:

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

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

    No recent polls found