As per perlunicode,
\p{Hiragana} will match a hiragana character when used in a regexp.
\p{Katakana} will match a katakana character when used in a regexp.
\p{Han} will match a kanji character when used in a regexp.
You can also negate those. See the referenced document.

Note that the text must have been decoded first (by using :encoding() on open, binmode or use open, or utf8::decode() or Encode::decode() or use utf8; for literals).

use strict; use warnings; use open ':std', ':locale'; $_ = <<"__EOI__"; \x{6F22}\x{5B57} \x{3072}\x{3089}\x{304C}\x{306A} \x{30AB}\x{30BF}\x{30AB}\x{30CA} __EOI__ my $hiragana = join ' ', /\p{Hiragana}+/g; my $katakana = join ' ', /\p{Katakana}+/g; my $kanji = join ' ', /\p{Han}+/g; print("hiragana: $hiragana\n"); print("katakana: $katakana\n"); print("kanji: $kanji\n");
hiragana: ひらがな
katakana: カタカナ
kanji:    漢字

In reply to Re: Japanese: detect hiragana/katakana/fulll width eisuuji by ikegami
in thread Japanese: detect hiragana/katakana/fulll width eisuuji by GaijinPunch

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.