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
|
349 Discussions
|
Please Login in order to post a comment
import re
S = input() k = input()
pattern = re.compile(f'(?={re.escape(k)})') matches = list(pattern.finditer(S))
if matches: for m in matches: print((m.start(), m.start() + len(k) - 1)) else: print((-1, -1))
Here is HackerRank Re.start() & Re.end() in Python solution - https://programmingoneonone.com/hackerrank-re-start-re-end-solution-in-python.html
You know what, I don't care about re on this one. It broke my brain. But here is a version that passed all the test cases without re: if name == "main": s: str = input() k: str = input()