There are only 27 entries because all the rest of the 256 entries map to themselves (Windows-1252 is a superset of Latin-1.) There are also some fallback entries that could be added that are not bidirectional. And of course there are thousand of Unicode characters that are not in Windows-1252, but what can you do about that?

UTF-8 is multibyte for codes >= x80, but those multiple bytes always have the high bit set! That's one of the nice features of UTF8. Of course you meant to say [\x80-\xff]. You can also easily tell the number of bytes per character just by looking at the first byte. See this table from RFC2279:

UCS-4 range (hex.) UTF-8 octet sequence (binary) 0000 0000-0000 007F 0xxxxxxx 0000 0080-0000 07FF 110xxxxx 10xxxxxx 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx 0001 0000-001F FFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx 0020 0000-03FF FFFF 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 0400 0000-7FFF FFFF 1111110x 10xxxxxx ... 10xxxxxx
If the high bit is set, then the number of consecutive ones following that is the number of bytes that follow. And all of those start with "10" so you can't confuse them with ASCII characters or with a leading byte of a UTF-8 sequence. Pretty easy!

If you notice, the lead byte of a multibyte sequence is going to be in the range [\xc0-\xfd]


In reply to Re: Re: Re: regex for utf-8 by Thelonius
in thread regex for utf-8 by jjohhn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.