2

perluniprops列出了它支持的 Unicode 版本的 Unicode 属性。对于 Perl 5.32.1,这是 Unicode 13.0.0。

您可以使用Unicode::Tussle获取与某个类别匹配的字符列表unichars

unichars '\p{Close_Punctuation}' 

和帮助:

$ unichars --help
Usage:
    unichars [*options*] *criterion* ...

    Each criterion is either a square-bracketed character class, a regex
    starting with a backslash, or an arbitrary Perl expression. See the
    EXAMPLES section below.

    OPTIONS:

     Selection Options:

        --bmp           include the Basic Multilingual Plane (plane 0) [DEFAULT]
        --smp           include the Supplementary Multilingual Plane (plane 1)
        --astral    -a  include planes above the BMP (planes 1-15)
        --unnamed   -u  include various unnamed characters (see DESCRIPTION)
        --locale    -l  specify the locale used for UCA functions

     Display Options:

        --category  -c  include the general category (GC=)
        --script    -s  include the script name (SC=)
        --block     -b  include the block name (BLK=)
        --bidi      -B  include the bidi class (BC=)
        --combining -C  include the canonical combining class (CCC=)
        --numeric   -n  include the numeric value (NV=)
        --casefold  -f  include the casefold status
        --decimal   -d  include the decimal representation of the code point

     Miscellaneous Options:

        --version   -v  print version information and exit
        --help      -h  this message
        --man       -m  full manpage
        --debug     -d  show debugging of criteria and examined code point span

     Special Functions:

         $_    is the current code point
         ord   is the current code point's ordinal

         NAME is charname::viacode(ord)
         NUM is Unicode::UCD::num(ord), not code point number
         CF is casefold->{status}
         NFD, NFC, NFKD, NFKC, FCD, FCC  (normalization)
         UCA, UCA1, UCA2, UCA3, UCA4 (binary sort keys)

         Singleton, Exclusion, NonStDecomp, Comp_Ex
         checkNFD, checkNFC, checkNFKD, checkNFKC, checkFCD, checkFCC
         NFD_NO, NFC_NO, NFC_MAYBE, NFKD_NO, NFKC_NO, NFKC_MAYBE

除了从网页中读取类别列表之外,还有没有办法以编程方式获取所有可能的\p{...}类别?

4

1 回答 1

2

\p从评论中,我相信您正在尝试将使用正则表达式属性的 Perl 程序移植到 Python。您不需要所有类别的列表(无论这意味着什么);您只需要知道程序使用的每个属性匹配的代码点。

现在,您可以从Unicode 数据库中获取代码点列表。但更简单的解决方案是使用 Python 的regex模块而不是re模块。这将使您能够访问 Perl 公开的相同 Unicode 定义的属性。

正则表达式模块的最新版本甚至使用 Unicode 13.0.0,就像最新的 Perl 一样。


注意程序使用\p{IsAlnum},写法比较长\p{Alnum}\p{Alnum}不是标准的 Unicode 属性,而是 Perl 扩展。它是 Unicode 属性\p{Alpha}\p{Nd}. 我不知道正则表达式模块是否定义Alnum相同,但它可能确实如此。

于 2021-04-19T07:07:31.783 回答