fork(5) download
  1. import re
  2. s = "hello a world today b is sunny c day"
  3. markers = "a b c".split()
  4. pattern = r'\b(' + ' (?:\w+ )?(?:\w+ )?'.join(markers) + r')\b'
  5. print(pattern)
  6. text = re.sub(pattern, r'<b>\1</b>', s)
  7. print(text)
  8. print(re.sub(r'\b' + ' (?:\w+ )?(?:\w+ )?'.join(markers) + r'\b', r'<b>\g<0></b>', s))
Success #stdin #stdout 0.02s 6988KB
stdin
Standard input is empty
stdout
\b(a (?:\w+ )?(?:\w+ )?b (?:\w+ )?(?:\w+ )?c)\b
hello <b>a world today b is sunny c</b> day
hello <b>a world today b is sunny c</b> day