使用perl检测汉字?

发布于 2024-11-28 08:16:48 字数 46 浏览 2 评论 0原文

有没有办法用 Perl 来检测汉字?有没有办法用符号点“.”来分割汉字?完美?

Is there any way to detect Chinese characters using Perl? And is there any way on how to split Chinese characters with symbol dot '.' perfectly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰之心 2024-12-05 08:16:48

取决于您对汉字的具体概念。也许您正在寻找 /\p{Script=Hani}/,但如果我们想要广泛传播,以下正则表达式模式将匹配中文书写中出现的内容。必要时进行限制。

use 5.014;
/
    (?: \p{Block=CJK_Compatibility}
    |   \p{Block=CJK_Compatibility_Forms}
    |   \p{Block=CJK_Compatibility_Ideographs}
    |   \p{Block=CJK_Compatibility_Ideographs_Supplement}
    |   \p{Block=CJK_Radicals_Supplement}
    |   \p{Block=CJK_Strokes}
    |   \p{Block=CJK_Symbols_And_Punctuation}
    |   \p{Block=CJK_Unified_Ideographs}
    |   \p{Block=CJK_Unified_Ideographs_Extension_A}
    |   \p{Block=CJK_Unified_Ideographs_Extension_B}
    |   \p{Block=CJK_Unified_Ideographs_Extension_C}
    )
/x;

是的,. 匹配一个字符。 split DWYM 的空模式:

use utf8;
split //, '冰淇淋'
# returns ('冰', '淇', '淋')

Depends on your particular notion of what is a Chinese character. Perhaps you're looking for /\p{Script=Hani}/, but if we want to cast our net wide, the following regex pattern will match stuff that occurs in Chinese writing. Restrict if necessary.

use 5.014;
/
    (?: \p{Block=CJK_Compatibility}
    |   \p{Block=CJK_Compatibility_Forms}
    |   \p{Block=CJK_Compatibility_Ideographs}
    |   \p{Block=CJK_Compatibility_Ideographs_Supplement}
    |   \p{Block=CJK_Radicals_Supplement}
    |   \p{Block=CJK_Strokes}
    |   \p{Block=CJK_Symbols_And_Punctuation}
    |   \p{Block=CJK_Unified_Ideographs}
    |   \p{Block=CJK_Unified_Ideographs_Extension_A}
    |   \p{Block=CJK_Unified_Ideographs_Extension_B}
    |   \p{Block=CJK_Unified_Ideographs_Extension_C}
    )
/x;

Yes, . matches one character. The empty pattern for split DWYM:

use utf8;
split //, '冰淇淋'
# returns ('冰', '淇', '淋')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文