Dear monks,

perlretut states:
The answer to requirement 2), as of 5.6.0, is that if a regexp contains Unicode characters, the string is searched as a sequence of Unicode characters. Otherwise, the string is searched as a sequence of bytes.
However, in Unicode, some character may be represented in more than one way, e.g. as a single code point, or as a combined character.
I assumed (probably wrongly) that in a regular expresion, perl would know a combined character to be "one" character. But it doesn't look like it:
#!/usr/bin/perl my @t = ("A\x{300}B", # U+0300 GRAVE ACCENT "AA", "A\x{41}\x{300}", # U+0041 LATIN CAPITAL LETTER A "\x{55}\x{308}O", # U+0308 COMBINING DIAERESIS "\x{dc}U" # U+00DC capital U with DIAERESIS ); binmode(STDOUT, ':utf8'); for (@t) { print "MATCH: $_\n" if /\p{Lu}{2}/; }

Uppercase characters represented by a single code point match. Combined characters match only if the combining mark isn't between the two characters. This is why
"A\x{300}B" doesn't match but "A\x{41}\x{300}" matches.

My question: is it possible to write regular expressions so that combined characters are treated as "single" characters by the regular expression engine?

Any help would be very appreciated.

In reply to unicode combined characters in regular expressions by telcontar

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.