304 North Cardinal St.
Dorchester Center, MA 02124

# Re.start() & Re.end() Hacker Rank Solution – Queslers

## Problem : Re.start() & Re.end() Hacker Rank Solution

These expressions return the indices of the start and end of the substring matched by the group.
Code :

``````>>> import re
>>> m = re.search(r'\d+','1234')
>>> m.end()
4
>>> m.start()
0
``````

You are given a string S.
Your task is to find the indices of the start and end of string k in S.

#### Input Format :

The first line contains the string S.
The second line contains the string k.

#### Constraints :

• 0 < len(s) < 100
• 0 < len(k) < len(s)

#### Output Format :

Print the tuple in this format: (start _index, end _index).
If no match is found, print (-1, -1).

#### Sample Input :

``````aaadaa
aa
``````

#### Sample Output :

``````(0, 1)
(1, 2)
(4, 5)``````

### Re.start() & Re.end() Hacker Rank Solution in python 2

``````import re
S = raw_input()
k = raw_input()
anymatch = 'No'
for m in re.finditer(r'(?=('+k+'))',S):
anymatch = 'Yes'
print (m.start(1),m.end(1)-1)
if anymatch == 'No':
print (-1, -1)``````

### Re.start() & Re.end() Hacker Rank Solution in python 3

``````# Enter your code here. Read input from STDIN. Print output to STDOUT
S = input()
k = input()
import re
pattern = re.compile(k)
r = pattern.search(S)
if not r: print("(-1, -1)")
while r:
print("({0}, {1})".format(r.start(), r.end() - 1))
r = pattern.search(S,r.start() + 1)``````

### Re.start() & Re.end() Hacker Rank Solution in pypy

``````# Enter your code here. Read input from STDIN. Print output to STDOUT
s1=raw_input()
s2=raw_input()
import re
pattern = re.compile(s2)
lenn=len(s1)

#print m
output=set([])

for i in range(lenn):
m=re.search(s2,s1[i:])
if m is None:
continue
if m.start()+i in output:
continue
else:
print (i+m.start(),i+m.end()-1)
if len(output)==0:
print (-1,-1)
#for n in m:
#    print n.start(), n.end()-1
#print m
``````

### Re.start() & Re.end() Hacker Rank Solution in pypy 3

``````import re
s, k = input(), input()
matches = list(re.finditer(r'(?={})'.format(k), s))
if matches:
print('\n'.join(str((match.start(),
match.start() + len(k) - 1)) for match in matches))
else:
print('(-1, -1)')``````
##### Re.start() & Re.end() Hacker Rank Solution Review:

In our experience, we suggest you solve this Re.start() & Re.end() Hacker Rank Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

Re.start() & Re.end() is available on Hacker Rank for Free, if you are stuck anywhere between compilation, just visit Queslers to get all Hacker Rank Solution

##### Re.start() & Re.end() Hacker Rank Solution Conclusion:

I hope this Re.start() & Re.end() Hacker Rank Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Hacker Rank, Leetcode, Codechef, Codeforce Solution.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Hacker Rank Problem & Solutions >>

Mini-Max Sum Hacker Rank Solution

String Validators Hacker Rank Solution

Text Alignment Hacker Rank solution

String validators Hacker Rank Solution