Regex 使用正则表达式中的Unicode范围作为Lex的规则

Regex 使用正则表达式中的Unicode范围作为Lex的规则,regex,unicode,python-3.x,lex,Regex,Unicode,Python 3.x,Lex,此代码段提供了一个声明非法字符的错误。所有字符都在正则表达式规则中指定的unicode范围内 有什么问题吗?提前谢谢 lexer应该能够在Unicode作为令牌和模式匹配规则的情况下正常工作。 如果您需要为re.compile()函数提供可选标志,请使用reflags选项 import re import ply.lex as lex #rest of the code def t_WORD(t): #WORD is a token defined in the tokens tuple

此代码段提供了一个声明非法字符的错误。所有字符都在正则表达式规则中指定的unicode范围内


有什么问题吗?提前谢谢

lexer应该能够在Unicode作为令牌和模式匹配规则的情况下正常工作。 如果您需要为re.compile()函数提供可选标志,请使用reflags选项

import re
import ply.lex as lex

#rest of the code

def t_WORD(t): #WORD is a token defined in the tokens tuple
    r'[\u0C80-\u0CFF]+'
    #rest of the actions
另请参见和

lex.lex(reflags=re.UNICODE)