import re START_ITEM = "" END_ITEM = "" TEXT = "1234567890" pattern = '%s(.*?)%s' % (START_ITEM, END_ITEM) string = '%s%s%s%s' % (START_ITEM, 200*TEXT, END_ITEM, 1*TEXT) # Find text inside item and after it res = re.search(pattern, string) inside_the_match = res.group(1) after_match = string[res.end():] actual = (inside_the_match, after_match) expected = (200*TEXT, 1*TEXT) assert actual == expected, "%s\n!=\n%s" % (actual, expected)