Let's say I have the following string:
s = "once upon a time, there was once a person"
Without using findall
to get all once
s in the string:
>>> re.findall(r'\bonce\b', s)
['once', 'once']
Is there a way to use search
incrementally, so it only returns the first occurrence and then increments the input string?
while (s):
x = re.search(r'\bonce\b', s) # return 'once' and increment the string to s[4:]
yield x