start() & end()

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

Task 

You are given a string $\mbox{S}$. 

Your task is to find the indices of the start and end of string $\boldsymbol{k}$ in $\mbox{S}$.

Input Format

The first line contains the string $\mbox{S}$. 

The second line contains the string $\boldsymbol{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)

Source: hackerrank | Difficulty: EASY


Solutions:
import re
s = input()
k = input()
m = re.search(k, s)
ind = 0
if not m:
	a = (-1, -1)
	print(a)
while m:
	a = (ind + m.start(), ind + m.start() + len(k) - 1)
	print(a)
	ind += m.start() + 1
	m = re.search(k, s[ind:])


import re
(s, regex) = (input(), input())
m = re.search(regex, s)
if not bool(m):
	print((-1, -1))
else:
	size = 0
	while bool(m):
		print((size + m.start(), size + m.end() - 1))
		size += m.start() + 1
		m = re.search(regex, s[size:])


import re
s = input().strip()
a = input().strip()
i = 0
m = re.search(a, s[i:])
if m:
	while m:
		print((i + m.start(), i + m.end() - 1))
		i += m.start() + 1
		m = re.search(a, s[i:])
else:
	print((-1, -1))


import re
s = input()
k = input()
i = re.finditer('(?={})'.format(k), s, flags=re.I)
found = False
kl = len(k)
for m in i:
	found = True
	print('({}, {})'.format(m.start(), m.start() + kl - 1))
if not found:
	print((-1, -1))


s = input()
k = input()
import re
m = re.finditer('(?=' + k + ')', s)
flag = 1
for i in m:
	flag = 0
	print('(', i.start(), ', ', i.end() + len(k) - 1, ')', sep='')
if flag:
	print('(-1, -1)')


import re
S = input()
k = input()
m = re.finditer('(?=' + k + ')', S)
matchSpans = [(mat.start(), mat.start() + len(k) - 1) for mat in m]
if len(matchSpans) == 0:
	print((-1, -1))
else:
	print(*matchSpans, sep='\n')


import re
S = input()
k = input()
found = False
for i in range(len(S)):
	m = re.match(k, S[i:])
	if m:
		found = True
		print('({}, {})'.format(i + m.start(), i + m.end() - 1))
if not found:
	print('(-1, -1)')


s = input()
k = input()
a = []
for i in range(len(s) - len(k) + 1):
	if s[i:i + len(k)] == k:
		a.append(i)
if a:
	for e in a:
		print((e, e + len(k) - 1))
else:
	print((-1, -1))


import re
test = input()
q = input().strip()
y = re.finditer('(?=({}))'.format(q), test)
z = []
for x in y:
	z.append((x.start(), x.start() + len(q) - 1))
if len(z) == 0:
	print((-1, -1))
else:
	for x in z:
		print(x)


import re

def foo(sub, s):
	if s == '':
		return []
	else:
		m = re.match(pat, s)
		rest = foo(sub, s[1:])
		if m == None:
			return [(i[0] + 1, i[1] + 1) for i in rest]
		else:
			return [(m.start(), m.end() - 1)] + [(i[0] + 1, i[1] + 1) for i in rest]
s = input().strip()
pat = input().strip()
res = foo(pat, s)
if res == []:
	print((-1, -1))
else:
	print(*res, sep='\n')


import re
S = input()
k = input()
if re.search(k, S) is None:
	print((-1, -1))
else:
	m = re.finditer('(?=(' + k + '))', S)
	for i in m:
		print((i.start(), i.end() + len(k) - 1))


import re

def __starting_point():
	string = input()
	sub = input()
	matches = list(re.finditer('(?={})'.format(sub), string))
	if matches:
		for match in matches:
			print((match.start(), match.end() + len(sub) - 1))
	else:
		print((-1, -1))
__starting_point()


import re
s = input()
r = input()
matches = []
for i in range(len(s)):
	if re.match(r, s[i:]):
		matches.append((i, i + len(r) - 1))
for item in matches:
	print(item)
if len(matches) == 0:
	print((-1, -1))


import sys, re
string = str(input().strip())
search = str(input().strip())
if not re.search(search, string):
	print('(-1, -1)')
else:
	search2 = re.compile(search[0] + '(?=' + search[1:] + ')')
	match_iter = re.finditer(search2, string)
	for m in match_iter:
		print('(' + str(m.start()) + ', ' + str(m.end() + len(search) - 2) + ')')


import re
(S, k) = (input(), input())
flag = True
for i in range(len(S)):
	res = re.search(k, S[i:i + len(k)])
	if res:
		flag = False
		print('(' + str(i + res.start()) + ', ' + str(i + res.end() - 1) + ')')
if flag:
	print('(-1, -1)')


import re
s = input()
rgx = input()
ms = list(re.finditer('(?=' + rgx + ')', s))
if not ms:
	print((-1, -1))
else:
	for m in ms:
		print((m.start(), m.end() + len(rgx) - 1))


import re
S = input()
k = input()
switch = True
for i in range(len(S)):
	m = re.match('(' + k + ')', S[i:])
	if bool(m):
		switch = False
		print((m.start() + i, m.end() + i - 1))
if switch:
	print((-1, -1))


import re
(s, k) = (input(), input())
(m, ms) = (re.finditer('(?=(%s))' % re.escape(k), s), re.findall('(?=(%s))' % re.escape(k), s))
print(*[(x.start(), x.start() + len(k) - 1) for x in m], sep='\n') if len(ms) > 0 else print((-1, -1))


import re
import sys
S = sys.stdin.readline().strip()
k = sys.stdin.readline().strip()
matches = list(re.finditer('(?=(%s))' % k, S))
if matches:
	for m in matches:
		print((m.start(), m.start() + len(m.group(1)) - 1))
else:
	print((-1, -1))


import re
(s, k) = (input(), input())
r = list(map(lambda x: (x.start(1), x.end(1) - 1), re.finditer('(?=(%s))' % k, s)))
[print(x) for x in r] if r else print((-1, -1))


(s, k) = (input().strip(), input().strip())

def show_item(x, y):
	print('(%d, %d)' % (x, y))
found = False
substr = ''
kl = len(k)
sl = len(s)
for i in range(0, sl - kl + 1):
	if i == 0:
		substr = s[0:kl]
	else:
		substr = substr[1:] + s[i + kl - 1:i + kl]
	if substr == k:
		show_item(i, i + kl - 1)
		found = True
if not found:
	show_item(-1, -1)


import re
S = input().strip()
k = input().strip()
results = list(map(lambda x: (x.start(), x.start() + len(k) - 1), re.finditer('(?=' + k + ')', S)))
if not results:
	print((-1, -1))
else:
	for t in results:
		print(t)


from sys import stdin as inp
import re
S = inp.readline().rstrip()
k = inp.readline().rstrip()
res = re.finditer('(?=(' + k + '))', S)
if re.search('(?=(' + k + '))', S):
	for m in res:
		print('(' + str(m.start(1)) + ', ' + str(m.end(1) - 1) + ')')
else:
	print('(-1, -1)')


import re
(S, k) = [input() for _ in range(2)]
m = list(re.finditer('(?=' + k + ')', S))
print(*([(i.start(), i.start() + len(k) - 1) for i in m] if m else [(-1, -1)]), sep='\n')


import re
s = input()
p = re.compile('(' + str(input()) + ')')
if p.search(s) is None:
	print((-1, -1))
else:
	i = 0
	while p.search(s, i) is not None:
		m = p.search(s, i)
		print((m.start(), m.end() - 1))
		i = m.start() + 1


import re
s = input()
k = input()
start = 0
end = 0
add_index = 0
prev = None
while True:
	f = re.search(k, s[add_index:])
	if not f:
		if add_index == 0:
			print((-1, -1))
		break
	start = f.start() + add_index
	end = f.end() - 1 + add_index
	add_index = end
	if (start, end) == prev:
		add_index += 1
	else:
		prev = (start, end)
		print((start, end))


import re
S = input()
k = input()
b = False
for each in range(len(S) - len(k) + 1):
	if S[each:each + len(k)] == k:
		print('(' + str(each) + ', ' + str(each + len(k) - 1) + ')')
		b = True
if b == False:
	print('(-1, -1)')


import re
(S, k) = (input(), input())
matches = re.finditer('(?=(' + k + '))', S)
anyPrint = False
for match in matches:
	anyPrint = True
	print((match.start(), match.start() + len(k) - 1))
if anyPrint == False:
	print((-1, -1))


import re
s = input()
srch = input()
iterator = re.finditer('(?=' + srch + ')', s)
if len(re.findall('(?=' + srch + ')', s)) > 0:
	for m in iterator:
		print('({0}, {1})'.format(m.start(), m.start() + len(srch) - 1))
else:
	print('(-1, -1)')


import re
st = input()
sr = input()
t = [(e.start(1), e.end(1) - 1) for e in re.finditer('(?=(%s))' % sr, st)]
if t:
	print(*t, sep='\n')
else:
	print((-1, -1))


import re
s = input()
subs = input()
results = list(map(lambda x: (x.start(1), x.end(1) - 1), re.finditer('(?=(%s))' % subs, s)))
if results:
	print(*results, sep='\n')
else:
	print((-1, -1))


import re
S = input()
k = input()
start = 0
found = False
while start < len(S):
	m = re.search(k, S[start:])
	if m:
		found = True
		print((start + m.start(), start + m.end() - 1))
		start += m.start() + 1
	else:
		break
if not found:
	print((-1, -1))


import re
S = input()
pattern = input()
result = []
for i in range(len(S)):
	m = re.match(pattern, S[i:])
	if m:
		result.append((i + m.start(), i + m.end() - 1))
		print((i + m.start(), i + m.end() - 1))
if not result:
	print((-1, -1))


import re
test = input()
pat = input()
p = re.compile(pat)
flag = 0
for i in range(len(test)):
	res = p.match(test[i:])
	if res:
		tup = (res.start() + i, res.end() + i - 1)
		print(tup)
		flag = 1
if flag == 0:
	print('(-1, -1)')


import re
S = input()
k = input()
c = 0
for i in re.finditer('(?=(%s))' % k, S):
	print((i.start(), i.start() + len(k) - 1))
	c += 1
if c == 0:
	print((-1, -1))


import re
my_string = str(input().strip())
my_substring = str(input().strip())
positions = 0
length1 = len(my_string)
printed = 0
while True:
	search_object = re.search(my_substring, my_string)
	if search_object == None:
		if printed == 0:
			print((-1, -1))
		break
	print((search_object.start() + positions, search_object.end() - 1 + positions))
	printed += 1
	positions += search_object.start() + 1
	my_string = my_string[search_object.start() + 1:]
	if len(my_string) < len(my_substring) or printed > length1:
		break


import re
s = input()
k = input()
flag = 0
for i in re.finditer('(?=' + k + ')', s):
	print((i.start(), i.start() + len(k) - 1))
	flag = 1
if flag == 0:
	print('(-1, -1)')


import re
S = input().rstrip()
pattern = re.compile(input().rstrip())
m = pattern.search(S)
if m == None:
	print((-1, -1))
while m != None:
	print((m.start(), m.end() - 1))
	m = pattern.search(S, m.start() + 1)


import re
S = input()
ss = input()
ci = re.finditer('(?=(' + ss + '))', S)
L = list(map(lambda x: (x.start(), x.start() + len(ss) - 1), ci))
if len(L) > 0:
	print(*L, sep='\n')
else:
	print((-1, -1))


import re
(s, k) = (input(), input())
kLen = len(k)
res = [(it.start(), it.start() + kLen - 1) for it in re.finditer('(?=(' + k + '))', s)]
if not res:
	res = [(-1, -1)]
print(*res, sep='\n')


import re
s = input()
k = input()
f = re.finditer('(?=' + k + ')', s)
d = len(k)
if re.search('(?=' + k + ')', s):
	[print('({0}, {1})'.format(m.start(), m.start() + d - 1)) for m in f]
else:
	print('(-1, -1)')


s = input()
k = input()
(a, b, c) = (0, 0, 0)
end = len(k) - 1
lim = len(s)
if k in s:
	while a != -1 and c < lim:
		a = s.find(k)
		if a != -1:
			c = a + b
			print((c, c + end))
			a += 1
			b += a
			s = s[a:]
else:
	print((-1, -1))


import re
(s, k) = (input(), input())
regex = re.compile(k)
match = regex.search(s)
if match == None:
	print('(-1, -1)')
else:
	while match != None:
		print('({0}, {1})'.format(match.start(), match.end() - 1))
		match = regex.search(s, match.start() + 1)


import re
(S, k) = (input(), input())
matches = re.finditer('(?=(' + k + '))', S)
anymatch = False
for match in matches:
	anymatch = True
	print((match.start(1), match.end(1) - 1))
if anymatch == False:
	print((-1, -1))


import re
S = input()
sub = input()
E = re.compile('(?=({}))'.format(sub))
m = re.finditer(E, S)
k = re.search(E, S)
if k == None:
	print('(-1, -1)')
else:
	[print('({}, {})'.format(p.start(), p.start() + len(sub) - 1)) for p in m]


import re
s = input()
k = input()
output = set()
for i in range(len(s)):
	m = re.search(k, s[i:])
	if m:
		output.add((m.start() + i, m.end() + i - 1))
print('\n'.join((str(x) for x in sorted(output))) if output else (-1, -1))


import re
(s, k) = (input(), input())
i = 0
while i < len(s):
	match = re.search(k, s[i:])
	if not i and (not match):
		print((-1, -1))
		break
	elif match:
		print((match.start() + i, match.end() + i - 1))
		i += match.start() + 1
	else:
		break


import re
(S, k) = (input().strip(), input().strip())
t = len(k) - 1
found = 0
for i in range(len(S) - t):
	if re.match(k, S[i:]):
		print((i, i + t))
		found = 1
if not found:
	print((-1, -1))


import re
S = input()
k = input()
m = re.search(k, S)
if not m:
	print((-1, -1))
offset = 0
while m:
	print((offset + m.start(), offset + m.end() - 1))
	offset += m.start() + 1
	m = re.search(k, S[offset:])


import re
s = input().strip()
k = input().strip()
s_len = len(s)
found_flag = False
for i in range(s_len):
	match_result = re.match(k, s[i:])
	if match_result:
		start_index = i + match_result.start()
		end_index = i + match_result.end() - 1
		print((start_index, end_index))
		found_flag = True
if found_flag == False:
	print('(-1, -1)')


import re
sf = input()
ss = input()
regex = re.compile(ss)
lastpos = 0
ms = []
while True:
	m = regex.search(sf, lastpos)
	if not m:
		break
	ms.append((m.start(), m.end() - 1))
	lastpos = m.start() + 1
if len(ms) > 0:
	print(*ms, sep='\n')
else:
	print((-1, -1))


import re
s = input()
p = input()
d = set()
for i in range(len(s)):
	m = re.match(p, s[i:])
	if m:
		indices = (m.start() + i, m.end() - 1 + i)
		d.add(indices)
if d:
	print(*sorted(list(d)), sep='\n')
else:
	print('(-1, -1)')


import re
S = input().strip()
k = input().strip()
m = re.finditer('(?=' + k + ')', S)
found = 0
if m:
	for mm in m:
		print('(%i, %i)' % (mm.start(), mm.start() + len(k) - 1))
		found = 1
if found == 0:
	print('(-1, -1)')


import re
S = input()
k = input()
result = re.finditer('(?=%s)' % k, S)
tupList = []
for match in result:
	tupList.append((match.start(), match.end() + len(k) - 1))
if tupList:
	for tup in tupList:
		print(tup)
else:
	print((-1, -1))


import re
S = input()
K = input()
coords = []
pos = 0
while True:
	m = re.search(re.escape(K), S[pos:])
	if not m:
		break
	coords.append('%s' % ((m.start() + pos, m.end() - 1 + pos),))
	pos += m.start() + 1
print('\n'.join(coords) or '(-1, -1)')


import re
string = input().strip()
substring = input().strip()
indices = [(m.start(), m.start() + len(substring) - 1) for m in re.finditer('(?=%s)' % substring, string)]
print('\n'.join([str(tup) for tup in indices]) if indices else (-1, -1))


import re
(s, k) = (input(), input())
l = []
for i in range(len(s) - len(k)):
	m = re.search(k, s[i:])
	if m:
		l.append(m.start() + i)
if l:
	for i in sorted(set(l)):
		print((i, i + len(k) - 1))
else:
	print((-1, -1))


import re
(S, k) = (input(), input())
rek = re.compile('(?=(' + k + '))')
m = rek.finditer(S)
if rek.search(S) == None:
	print('(-1, -1)')
else:
	for i in m:
		strt_indx = i.start()
		print('({}, {})'.format(strt_indx, strt_indx + len(k) - 1))


import re
s = input()
t = input()
i = 0
m = re.search(t, s)
if not m:
	print((-1, -1))
while m:
	print((m.start(), m.end() - 1))
	m = re.search('(?<=.{' + str(m.start() + 1) + '})' + t, s)


import re
s = input().strip()
k = input().strip()
reg = '(?=(' + k + '))'
if re.search(k, s) == None:
	print('(-1, -1)')
else:
	print('\n'.join((str(tuple([m.start(), m.start() + len(k) - 1])) for m in re.finditer(reg, s))))


import sys
if sys.version_info[0] >= 3:
	raw_input = input
s = raw_input().strip()
t = raw_input().strip()
a = [i for i in range(len(s) - len(t) + 1) if s[i:i + len(t)] == t]
if a:
	for e in a:
		print((e, e + len(t) - 1))
else:
	print((-1, -1))


import re
s = input('')
subs = input('')
results = list(map(lambda x: (x.start(1), x.end(1) - 1), re.finditer('(?=(%s))' % subs, s)))
if results:
	for i in results:
		print(i)
else:
	print('(-1, -1)')


import re
(s, k) = (input(), input())
x = list(re.finditer('(?=' + k + ')', s))
if len(x):
	for m in x:
		print('({}, {})'.format(m.start(), m.start() + len(k) - 1))
else:
	print('(-1, -1)')


import re
s = input()
k = input()
results = list(map(lambda x: (x.start(1), x.end(1) - 1), re.finditer('(?=(%s))' % k, s)))
if results:
	print(*results, sep='\n')
else:
	print('(-1, -1)')


import re
a_str = input()
substr = input()
p = re.compile('' + substr + '')
a_list = []
for i in range(len(a_str)):
	search_pos = a_list[-1][0] + 1 if len(a_list) else i
	m = p.search(a_str, search_pos)
	if m:
		a_list.append((m.start(), m.end() - 1))
		if len(a_list) >= 2:
			if a_list[i] == a_list[i - 1]:
				a_list.pop()
				break
print('\n'.join(map(str, a_list)) if a_list else (-1, -1))


import re
(s, k) = (input(), re.compile(input()))
m = k.search(s)
if not m:
	print((-1, -1))
while m:
	print((m.start(), m.end() - 1))
	m = k.search(s, m.start() + 1)


import sys
import re

def vn():
	s = input().strip()
	subs = input().strip()
	len_subs = len(subs)
	pos = 0
	while len(s) >= len_subs:
		m = re.search(subs, s)
		if not m:
			if not pos:
				print((-1, -1))
			return
		start = m.start()
		end = m.end() - 1
		s = s[start + 1:]
		print((pos + start, pos + end))
		pos += start + 1
	return

def main():
	vn()
	return
main()


import re
(S, k) = (input().strip(), input().strip())
r = []
for i in range(len(S)):
	m = re.match(k, S[i:])
	if m is not None:
		r.append((i + m.start(), i + m.end() - 1))
		print((i + m.start(), i - 1 + m.end()))
if not r:
	print((-1, -1))


import re
a = input()
b = input()
p = re.compile(b)
m = p.search(a)
if m:
	while m:
		print((m.start(), m.end() - 1))
		m = p.search(a, m.start() + 1)
else:
	print((-1, -1))


import re
s = input()
t = input()
x = re.compile('(?=(%s))' % t)
if x.search(s):
	for i in x.finditer(s):
		print((i.start(1), i.end(1) - 1))
else:
	print((-1, -1))


import re
(s, k) = (input(), input())
k = '(?=(' + k + '))'
m = re.finditer(k, s)
a = ''
for e in m:
	a += str(tuple([e.start(1), e.end(1) - 1]))
	a += '\n'
if a == '':
	print('(-1, -1)')
else:
	print(a.strip())


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


import re
s = input()
sub = input()
found = False
length = len(sub) - 1
matches = re.finditer('(?=(' + sub + '))', s)
results = [(match.start(), match.start() + length) for match in matches]
if results:
	print(*results, sep='\n')
else:
	print((-1, -1))


s = input()
t = input()
a = [i for i in range(len(s) - len(t) + 1) if s[i:i + len(t)] == t]
if a:
	for e in a:
		print((e, e + len(t) - 1))
else:
	print((-1, -1))


import re
s = input()
k = input()
start = 0
dif = 0
while True:
	m = re.search(k, s[start:])
	if bool(m):
		start = dif + m.start() + 1
		print((dif + m.start(), dif + m.end() - 1))
		dif += m.start() + 1
	else:
		if dif == 0:
			print((-1, -1))
		break


from re import *
S = input().strip()
subS = input().strip()
match = list(map(lambda x: (x.start(1), x.end(1) - 1), finditer('(?=(%s))' % subS, S)))
if match:
	for item in match:
		print(item)
else:
	print(str(tuple([-1, -1])))


import re
s = input()
k = input()
kl = len(k)
kll = kl
c = 0
for i in range(len(s) - 1):
	l = []
	sp = s[i:kl]
	kl += 1
	if sp == k:
		c += 1
		l.append(i)
		l.append(i + kll - 1)
		t = tuple(l)
		print(t)
if c == 0:
	t = (-1, -1)
	print(t)


import re
s = input().strip()
k = input().strip()
offset = 0
while offset < len(s):
	m = re.search(k, s[offset:])
	if m:
		print((m.start() + offset, m.end() + offset - 1))
		offset = m.start() + offset + 1
	else:
		break
if offset == 0:
	print((-1, -1))


import re
(s, ptn) = (input(), input())
matches = []
for x in range(len(s)):
	m = re.match(ptn, s[x:])
	if m is not None:
		matches.append((x + m.start(), x + m.end() - 1))
if not any(matches):
	print((-1, -1))
else:
	for x in matches:
		print(x)


import re
s = input()
k = input()
f = re.finditer('(?=' + k + ')', s)
for m in f:
	print('({0}, {1})'.format(m.start(), m.start() + len(k) - 1))
if re.search('(?=' + k + ')', s) == None:
	print('(-1, -1)')


import re
s = input().strip()
k = input().strip()
li = set()
for i in range(len(s)):
	result = re.search(k, s[i:])
	if result:
		li.add(tuple([result.start() + i, result.end() - 1 + i]))
for i in li:
	print(i)
if len(li) == 0:
	print(tuple([-1, -1]))


import re
(S, k) = (input(), input())
patterns = list(re.finditer('(?=' + k + ')', S))
if len(patterns) == 0:
	print((-1, -1))
else:
	for found in patterns:
		print((found.start(), found.start() + len(k) - 1))


import re
(S, k) = (input(), input())
o = len(k) - 1
printed = False
for m in re.finditer('(?=({}))'.format(re.escape(k)), S):
	s = m.start()
	print((s, s + o))
	printed = True
if not printed:
	print((-1, -1))


import re
string = input()
pattern = input()
temp = 0
m = re.search(pattern, string)
if m == None:
	print('(-1, -1)')
while m:
	print('({}, {})'.format(temp + m.start(), temp + m.end() - 1))
	string = string[m.start() + 1:]
	temp += m.start() + 1
	m = re.search(pattern, string)


import re
(S, k) = (input().strip(), input().strip())
l = len(k) - 1
L = [(x.start(), x.start() + l) for x in re.finditer('(?=' + k + ')', S)]
if L == []:
	print('(-1, -1)')
else:
	print(*L, sep='\n')


import re
S = input()
k = input()
no_match = True
for m in re.finditer('(?={})'.format(k), S):
	print('({}, {})'.format(m.start(), m.start() + len(k) - 1))
	no_match = False
if no_match:
	print('(-1, -1)')


import re
tmp = '(-1, -1)'
x = input()
match = input()
m = list(map(lambda a: (a.start(1), a.end(1) - 1), re.finditer('(?=(%s))' % match, x)))
if m:
	for x in m:
		print(x)
else:
	print(tmp)


import re

def main():
	a = input()
	b = input()
	ans = set()
	for i in range(len(a)):
		m = re.search(b, a[i:])
		if m:
			ans.add((m.start() + i, m.end() + i - 1))
	if ans:
		for s in sorted(ans):
			print(s)
	else:
		print((-1, -1))
main()


import re
s = input()
k = input()
matches = list(re.finditer('(?=(' + k + '))', s))
if matches:
	for match in matches:
		print((match.start(), match.start() + len(k) - 1))
else:
	print((-1, -1))


import re
S = input()
k = input()
kLen = len(k)
myRegEx = re.compile('(?=' + k + ')')
m = myRegEx.finditer(S)
mEmpty = True
for x in m:
	mEmpty = False
	print((x.start(), x.start() + kLen - 1))
if mEmpty:
	print((-1, -1))


import re
s = input()
k = input()
p = '(?=%s)' % k
m = re.finditer(p, s)
for match in m:
	print((match.start(), match.start() + len(k) - 1))
if not re.search(p, s):
	print((-1, -1))


import re
s = input()
test = input()
n = len(test)
if re.search(test, s):
	for k in range(len(s)):
		if s[k:k + n] == test:
			print((k, k + n - 1))
else:
	print('(-1, -1)')