fork download
  1. import re
  2. strs = ['this_and', 'this.and', '(and)', '[and]', 'and^', ';And', 'land', 'andy']
  3. phrase = "and"
  4. rx = re.compile(r'(?<![^\W_]){}(?![^\W_])'.format(re.escape(phrase)), re.I)
  5. for s in strs:
  6. print("{}: {}".format(s, bool(rx.search(s))))
Success #stdin #stdout 0.02s 27728KB
stdin
Standard input is empty
stdout
this_and: True
this.and: True
(and): True
[and]: True
and^: True
;And: True
land: False
andy: False