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.
Re.start() & Re.end()
Re.start() & Re.end()
Sort by
recency
|
340 Discussions
|
Please Login in order to post a comment
why did you add len(K)-1 . ?
match.start() + len(K) - 1
len(K) tells us how many characters there are in K. We subtract 1 because indices in Python start from 0, so the last index of the match will be match.start() + len(K) - 1.
Different approach :
import re
s = input() k = input() pattern = rf"(?=({re.escape(k)}))" if matches := list(re.finditer(pattern, s)):
else: print((-1, -1))