匹配'\uFFFF'上所有unicode字符的正则表达式

2024-10-16 17:25:38 发布

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

当我得到UCS-4角色时,Pygame和Pyglet都崩溃了:

exceptions.UnicodeError: A Unicode character above '\uFFFF' was found; not supported

如何使用regex过滤所有这些字符?在


Tags: 角色unicodenotpygameregexexceptionsabovepyglet
2条回答

尽管这是一个最合适的regex工具,但它问的问题并不合适。您可以迭代变量中的每个字符使用ord(c) > 0xFFFF来检测有问题的字符。在

但是如果您需要regex,请尝试(python3)

import re
r1 = re.compile("[\U00010000-\U0010FFFF]")
m1 = r1.search( "Text\u00A0\U0001FFFF" )
print (m1.group())
print (m1.start())
print (m1.end())

对于python2,只需在字符串文字之前添加“u”(使其成为unicode)。在

字体可能是这里真正的问题,所以我不确定用regex过滤会给你带来什么好处。我建议您看看^{}模块,因为它不限制使用\uFFFF范围以上的代码点。在

To use the pygame.freetypeEnhanced Pygame module for loading and rendering computer fonts based pygame.ftfont as pygame.fontpygame module for loading and rendering fonts define the enviroment variable PYGAME_FREETYPE before the first import of pygamethe top level pygame package. pygame.ftfont is a pygame.fontpygame module for loading and rendering fonts compatible module that passes all but one of the font module unit tests: it does not have the UCS-2 limitation of the SDL_ttf based font module, so fails to raise an exception for a code point greater than ‘uFFFF’. If pygame.freetypeEnhanced Pygame module for loading and rendering computer fonts is unavailable then the SDL_ttf font module will be loaded instead.

http://www.pygame.org/docs/ref/font.html

相关问题 更多 >