e-s*_*tis 3 python regex unicode rawstring
编辑:一旦你拿起"r"标志的含义,这个问题就没有意义了.更多细节在这里.对于寻找快速安全的人,我在下面补充道.
如果我在Python脚本中手动输入正则表达式,我可以为模式字符串使用4种标志组合:
我有一堆来自Web表单输入的unicode字符串,并希望将它们用作regexp模式.
我想知道我应该对字符串应用什么过程,所以我可以期望使用上面的手册形式得到类似的结果.就像是 :
import re
assert re.match(p1, some_text) == re.match(someProcess1(web_input), some_text)
assert re.match(p2, some_text) == re.match(someProcess2(web_input), some_text)
assert re.match(p3, some_text) == re.match(someProcess3(web_input), some_text)
assert re.match(p4, some_text) == re.match(someProcess4(web_input), some_text)
Run Code Online (Sandbox Code Playgroud)
someProcess1到someProcessN会是什么?为什么?
我想someProcess2不需要做任何事情,而someProcess1应该做一些unicode转换到本地编码.对于原始字符串文字,我无能为力.
除了可能必须正确编码Unicode(在Python 2.*中)之外,不需要任何处理,因为"原始字符串" 没有特定的类型 - 它只是文字的语法,即字符串常量,而你不是你的代码片段中有任何字符串常量,因此没有什么可以"处理".