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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Python
  3. Regex and Parsing
  4. Re.start() & Re.end()
  5. Discussions

Re.start() & Re.end()

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 302 Discussions, By:

recency

Please Login in order to post a comment

  • albert_su_17
    2 weeks ago+ 0 comments
    import re
    s, p = input(), re.compile(input())
    start, end = -1,-1
    while 1:
            result = p.search(s,start+1)
            if result:
                    start = result.start()
                    end = result.end()-1
                    print((start,end))
            else:
                    if start < 0:
                            print((start,end))
                    break
    
    0|
    Permalink
  • thamminidirupa
    2 weeks ago+ 0 comments

    Enter your code here. Read input from STDIN. Print output to STDOUT

    import re

    string = input() substring = input()

    pattern = re.compile(substring) match = pattern.search(string) if not match: print('(-1, -1)') while match: print('({0}, {1})'.format(match.start(), match.end() - 1)) match = pattern.search(string, match.start() + 1)

    0|
    Permalink
  • upendra8sai7
    3 weeks ago+ 0 comments

    import re s = input() k = input() pattern = re.compile(k) match = pattern.search(s) if match == None: print((-1, -1)) else: for i in range(0, len(s)): a = pattern.match(s, pos=i, endpos=i+len(k)) if a: print((a.span()[0], a.span()[-1]-1))

    0|
    Permalink
  • whidalgohp
    3 weeks ago+ 0 comments
    import re
    
    S=input()
    k=input()
    
    reg_ex=f'{k[0]}(?={k[1:]})'
    m_n=re.findall(reg_ex,S)
    m = re.finditer(reg_ex,S)
    
    if len(m_n):
        for i in m:
            start=i.start()
            end=start+len(k)-1
            tupla=(start,end)
            print(tupla)
    else:
        print((-1,-1))
    
    0|
    Permalink
  • DinuAr
    1 month ago+ 0 comments
    import re
    
    s = input()
    d = input()
    
    m = re.search(d, s)
    output = []
    while m:
      start_index = m.start()
      end_index = m.end()
      output.append("("+str(start_index)+", "+str(end_index-1)+")")
      s = s.replace(s[start_index], "0", 1)
      m = re.search(d, s)
    
    if output:
      output = list(set(output))
      output.sort()
    
      for i in output:
        print(i)
    else:
      print("(-1, -1)")
    
    1|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy