简体   繁体   English

在 python 3 中 re.search(r'pattern, string') 和 re.search(b'pattern, string) 有什么区别

[英]In python 3 what is the difference between re.search(r'pattern, string') and re.search(b'pattern, string)

In python 3 what is the difference between re.search(r'pattern, string') and re.search(b'pattern, string)在 python 3 中 re.search(r'pattern, string') 和 re.search(b'pattern, string) 有什么区别

I would be interested if someone would kindly point me to where this is documented.如果有人愿意指出我记录在哪里,我会很感兴趣。

r'pattern' will look into a "raw" string, which if you have backslash, it will not interpret it as an escape character. r'pattern' 将查看“原始”字符串,如果您有反斜杠,它不会将其解释为转义字符。

b'pattern' will look into a "byte" string, which is a string that is encoded. b'pattern' 将查找“字节”字符串,该字符串是经过编码的字符串。

So re.search will do the same for both, but in r'' it will analyze a raw string and in b'' it will analyze bytes.所以 re.search 将对两者都做同样的事情,但是在 r'' 中它将分析原始字符串,而在 b'' 中它将分析字节。

Edit: here is the documentation on it -> Lexical Analysis编辑:这里是它的文档->词法分析

r'pattern' is a stringliteral while b'pattern' is a bytesliteral r'pattern'stringliteralb'pattern'bytesliteral

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM