python中perluniprops的等价性是什么?

2024-10-01 02:38:48 发布

您现在位置:Python中文网/ 问答频道 /正文

在^{cd1>}中,有Unicode 7的^{cd2>}索引,http://perldoc.perl.org/perluniprops.html在这里,我可以执行以下操作来填充开头和结束标点:

s/(\p{Open_Punctuation})/ $1 /g;
s/(\p{Close_Punctuation})/ $1 /g;

使用perl时填充的打开/结束标点的完整列表是什么?^{cd3>}中的等价性是什么?

相关问题:Padding multiple character with space - pythonPadding multiple character with space - python;这个问题是由回答者投票分开提出的,它应该是单独的。


Tags: orghttphtmlwithunicodespacemultipleperl
1条回答
网友
1楼 · 发布于 2024-10-01 02:38:48

你在问如何确定一个给定的开放标点对应的结束标点是什么?Unicode没有对此进行定义。事实上,甚至没有1:1的关系。在

$ unichars '\p{Open_Punctuation}' | wc -l
75

$ unichars '\p{Close_Punctuation}' | wc -l
73

但是,您应该相对容易地构建自己的映射。在

^{pr2}$

^{3}$

使用cpan Unicode::Tussle安装unichars后,在python中:

>>> import subprocess
>>> cmd = "unichars '\p{Open_Punctuation}' | cut -f2 -d' ' | tr -d '\n'"
>>> open_punct = subprocess.check_output(cmd, shell=True).decode('utf8')
Smartmatch is experimental at /usr/local/bin/unichars line 546.
>>> print (open_punct)
([{༺༼᚛‚„⁅⁽₍〈❨❪❬❮❰❲❴⟅⟦⟨⟪⟬⟮⦃⦅⦇⦉⦋⦍⦏⦑⦓⦕⦗⧘⧚⧼⸢⸤⸦⸨〈《「『【〔〖〘〚〝﴾︗︵︷︹︻︽︿﹁﹃﹇﹙﹛﹝([{⦅「

相关问题 更多 >