【发布时间】:2016-09-26 09:16:46
【问题描述】:
我从用户那里得到一个输入正则表达式,它被保存为一个 unicode 字符串。在将输入字符串编译为正则表达式对象之前,我是否必须将其转换为原始字符串?还是没有必要?我是否将其正确转换为原始字符串?
import re
input_regex_as_unicode = u"^(.){1,36}$"
string_to_check = "342342dedsfs"
# leave as unicode
compiled_regex = re.compile(input_regex_as_unicode)
match_string = re.match(compiled_regex, string_to_check)
# convert to raw
compiled_regex = re.compile(r'' + input_regex_as_unicode)
match_string = re.match(compiled_regex, string_to_check)
@Ahsanul Haque,我的问题是更具体的正则表达式,正则表达式在将其转换为正则表达式对象时是否正确处理 unicode 字符串
【问题讨论】:
-
@Ahsanul Haque,我的问题是更具体的正则表达式,正则表达式在将其转换为正则表达式对象时是否正确处理 unicode 字符串。
标签: python regex python-2.7