fork download
  1. import re
  2. key = "hello world is a good idea for a T-shirt"
  3. pat = r"\W+".join([re.escape(x) for x in key.split()])
  4. print(pat)
  5. text = "This is some string, that includes commas, and other punctuations. It also includes hello world, is a, good, idea for a T-shirt and other."
  6. match = re.search(pat, text)
  7. if match:
  8. print("YES!")
Success #stdin #stdout 0s 23304KB
stdin
Standard input is empty
stdout
hello\W+world\W+is\W+a\W+good\W+idea\W+for\W+a\W+T\-shirt
YES!