有没有办法列出 perluniprops 中的所有类别?
Is there a way to list all categories in perluniprops?
perluniprops lists the Unicode properties of the version of Unicode it supports. For 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{...}
类别?
根据评论,我相信您正在尝试将使用 \p
正则表达式属性的 Perl 程序移植到 Python。您不需要所有类别的列表(无论那是什么意思);您只需要知道程序使用的每个 属性 匹配的代码点。
现在,您可以从 Unicode database. But a much simpler solution is to use Python's regex module instead of the re 模块中获取代码点列表。这将使您能够访问 Perl 公开的相同 Unicode 定义的属性。
最新版本的 regex 模块甚至像最新的 Perl 一样使用 Unicode 13.0.0。
注意程序使用了\p{IsAlnum}
,写法很长\p{Alnum}
。 \p{Alnum}
不是标准的 Unicode 属性,而是 Perl 扩展。它是 Unicode 属性 \p{Alpha}
和 \p{Nd}
的联合。我不知道 regex 模块是否相同地定义了 Alnum
,但它可能确实如此。
perluniprops lists the Unicode properties of the version of Unicode it supports. For 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{...}
类别?
根据评论,我相信您正在尝试将使用 \p
正则表达式属性的 Perl 程序移植到 Python。您不需要所有类别的列表(无论那是什么意思);您只需要知道程序使用的每个 属性 匹配的代码点。
现在,您可以从 Unicode database. But a much simpler solution is to use Python's regex module instead of the re 模块中获取代码点列表。这将使您能够访问 Perl 公开的相同 Unicode 定义的属性。
最新版本的 regex 模块甚至像最新的 Perl 一样使用 Unicode 13.0.0。
注意程序使用了\p{IsAlnum}
,写法很长\p{Alnum}
。 \p{Alnum}
不是标准的 Unicode 属性,而是 Perl 扩展。它是 Unicode 属性 \p{Alpha}
和 \p{Nd}
的联合。我不知道 regex 模块是否相同地定义了 Alnum
,但它可能确实如此。