HackerRank Python - Re.start() & Re.end()




start() & end()
These expressions return the indices of the start and end of the substring matched by the group.



  1. # Enter your code here. Read input from STDIN. Print output to STDOUT
  2. import re
  3. string = input()
  4. substring = input()
  5. pattern = re.compile(substring)
  6. match = pattern.search(string)
  7. if not match: print('(-1, -1)')
  8. while match:
  9. print('({0}, {1})'.format(match.start(), match.end() - 1))
  10. match = pattern.search(string, match.start() + 1)
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution






codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube