match
only search the pattern at the beginning of the string, if you want to find out if a string contains a pattern, use search
instead. Besides you don't need the word boundary, \b
:
re.search(pattern, string, flags=0)
Scan through string looking for
the first location where the regular expression pattern produces a
match, and return a corresponding match object. Return None if no
position in the string matches the pattern; note that this is
different from finding a zero-length match at some point in the
string.
re.match(pattern, string, flags=0)
If zero or more characters at the
beginning of string match the regular expression pattern, return a
corresponding match object. Return None if the string does not match
the pattern; note that this is different from a zero-length match.
import re
if re.search(r"a%1b", "xa%1bc"):
print("hello")
# hello