1
>>> a = """if HELLO
... do something"""
>>> b = b"""if HELLO
... do something"""
>>> if re.search(r"HELLO\b", a):
...     print('yes')
...
yes
>>> if re.search(b"HELLO\b", b):
...     print('yes')
...
>>>

Is there any way to use \b when searching through bytestrings? Or is there another option that does the same thing as \b?

Takkun
  • 6,131
  • 16
  • 52
  • 69
  • 1
    The answer is [yes](https://ideone.com/Elsbiv). Use `\\b` in a regular string litetral or `\b` in a raw string literal (as you already are using) – Wiktor Stribiżew Jun 11 '18 at 13:07
  • To be clear, the literal modifiers are stackable; `rb'HELLO\b'` and `br'HELLO\b'` are both equivalent raw `bytes` literals (only the latter is supported on Py2 IIRC, but both are supported on any reasonably modern Py3). – ShadowRanger Jun 11 '18 at 13:22

0 Answers0