We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
While Python doesn't provide a way to count number of overlapping occurance, we can use regex to that with lookahead.
The concept it to iter over all elements and check if ahead of every chsrector is our sub_string. Since we are using lookahead the pointor or cursor doesn't move for checking hence next element will not be after the match rather just next index item.
For this regex is: f'(?={sub_string})' where f is to make this fromated string and replce {substring} with sub_string.
Find a string
You are viewing a single comment's thread. Return to all comments →
While Python doesn't provide a way to count number of overlapping occurance, we can use regex to that with lookahead.
The concept it to iter over all elements and check if ahead of every chsrector is our
sub_string
. Since we are using lookahead the pointor or cursor doesn't move for checking hence next element will not be after the match rather just next index item.For this regex is:
f'(?={sub_string})'
where f is to make this fromated string and replce{substring}
withsub_string
.