简体   繁体   中英

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)

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.

b'pattern' will look into a "byte" string, which is a string that is encoded.

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.

Edit: here is the documentation on it -> Lexical Analysis

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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