Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何退出r.match的db regex模式_Python_Regex_Rethinkdb - Fatal编程技术网

Python 如何退出r.match的db regex模式

Python 如何退出r.match的db regex模式,python,regex,rethinkdb,Python,Regex,Rethinkdb,我想使用用户输入在数据库中使用r.match进行搜索-整个用户输入应被视为搜索模式。我根据用户输入创建正则表达式,如下所示: pattern = u'.*(?i){0}.*'.format(user_input) 但是,如果用户输入“[”或“]”或任何其他特殊字符,我会从“重新思考”中得到如下错误: pattern = u'.*(?i){0}.*'.format(user_input) regexp.*i\u0141[.*部分[.*缺失]:[.]中出现错误: 有没有办法转义RejectDB的

我想使用用户输入在数据库中使用r.match进行搜索-整个用户输入应被视为搜索模式。我根据用户输入创建正则表达式,如下所示:

pattern = u'.*(?i){0}.*'.format(user_input)
但是,如果用户输入“[”或“]”或任何其他特殊字符,我会从“重新思考”中得到如下错误:

pattern = u'.*(?i){0}.*'.format(user_input)
regexp.*i\u0141[.*部分[.*缺失]:[.]中出现错误:

有没有办法转义RejectDB的正则表达式?我曾尝试使用python re.escape,但在将unicode与以下错误结合时失败:

regexp.*i\\u0141.*部分\\u0141中的错误:无效的转义序列:\u0141

有什么建议吗?

使用re.escape功能:

逃税

返回所有非字母数字都反斜杠的字符串;如果要匹配可能包含正则表达式元字符的任意文字字符串,此选项非常有用


我曾试图这样做,但在使用unicode时,我遇到了如下错误:regexp.*I\\u0141.*partion\\u0141:无效的转义序列:\u0141我不知道这是否仍然与您相关,因为这个问题是在4年前提出的,但万一其他人偶然发现它,我也遇到了同样的问题,并找到了解决方法:希望它能解决回答你的问题并解开这个谜团。