Do regular expressions from the re module support word boundaries (\b)?

前端 未结 4 616
闹比i
闹比i 2020-11-22 03:38

While trying to learn a little more about regular expressions, a tutorial suggested that you can use the \\b to match a word boundary. However, the following sn

4条回答
  •  误落风尘
    2020-11-22 03:52

    This will work: re.search(r"\btwo\b", x)

    When you write "\b" in Python, it is a single character: "\x08". Either escape the backslash like this:

    "\\b"
    

    or write a raw string like this:

    r"\b"
    

提交回复
热议问题