group()

A group() expression returns one or more subgroups of the match. 

Code

>>> import re
>>> m = re.match(r'(\w+)@(\w+)\.(\w+)','username@hackerrank.com')
>>> m.group(0)       # The entire match 
'username@hackerrank.com'
>>> m.group(1)       # The first parenthesized subgroup.
'username'
>>> m.group(2)       # The second parenthesized subgroup.
'hackerrank'
>>> m.group(3)       # The third parenthesized subgroup.
'com'
>>> m.group(1,2,3)   # Multiple arguments give us a tuple.
('username', 'hackerrank', 'com')

groups()

A groups() expression returns a tuple containing all the subgroups of the match. 

Code

>>> import re
>>> m = re.match(r'(\w+)@(\w+)\.(\w+)','username@hackerrank.com')
>>> m.groups()
('username', 'hackerrank', 'com')

groupdict()

A groupdict() expression returns a dictionary containing all the named subgroups of the match, keyed by the subgroup name. 

Code

>>> m = re.match(r'(?P<user>\w+)@(?P<website>\w+)\.(?P<extension>\w+)','myname@hackerrank.com')
>>> m.groupdict()
{'website': 'hackerrank', 'user': 'myname', 'extension': 'com'}

Task  

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

Your task is to find the first occurrence of an alphanumeric character in $\mbox{S}$ (read from left to right) that has consecutive repetitions. 

Input Format

A single line of input containing the string $\mbox{S}$.

Constraints

$0<len(S)<100$

Output Format

Print the first occurrence of the repeating character. If there are no repeating characters, print -1.

Sample Input
..12345678910111213141516171820212223

Sample Output
1

Explanation

.. is the first repeating character, but it is not alphanumeric. 

1 is the first (from left to right) alphanumeric repeating character of the string in the substring 111.

Difficulty: EASY

Solutions:
import re
ip = input()
m = re.match('.*?(?P<user>[0-9A-Za-z])\\1+', ip)
if m == None:
	print(-1)
else:
	for (key, val) in m.groupdict().items():
		print(val)


import re
line = input().strip()
m = re.search('([a-zA-Z0-9])\\1+', line)
print(m.group(1) if m else -1)


import re
N = str(input())
m = re.search('([a-zA-Z0-9])\\1+', N)
print(m.group(1) if m else -1)


import re
a = re.search('([a-zA-Z0-9])\\1+', input())
if a != None:
	print(a.group(0)[0])
else:
	print('-1')


import re
S = input()
r = re.findall('(A+)|(B+)|(C+)|(D+)|(E+)|(F+)|(G+)|(H+)|(I+)|(J+)|(K+)|(L+)|(M+)|(N+)|(O+)|(P+)|(Q+)|(R+)|(S+)|(T+)|(U+)|(V+)|(W+)|(X+)|(Y+)|(Z+)|(a+)|(b+)|(c+)|(d+)|(e+)|(f+)|(g+)|(h+)|(i+)|(j+)|(k+)|(l+)|(m+)|(n+)|(o+)|(p+)|(q+)|(r+)|(s+)|(t+)|(u+)|(v+)|(w+)|(x+)|(y+)|(z+)|(0+)|(1+)|(2+)|(3+)|(4+)|(5+)|(6+)|(7+)|(8+)|(9+)', S)
b = False
for each in range(len(r)):
	for j in range(len(r[each])):
		if len(r[each][j]) > 1 and b == False:
			print(r[each][j][0])
			b = True
			break
if b == False:
	print(-1)


import re
s = input()
m = re.search('([a-zA-Z0-9])\\1', s)
if not m:
	print('-1')
else:
	print(m.group(0)[0])


import re, sys
s = input()
reg = re.compile('([a-z0-9])\\1')
mo = reg.search(s)
if mo != None:
	print(mo.group(1))
else:
	print(-1)


import re
m = re.search('([A-Za-z0-9])\\1', input())
if m:
	print(m.groups()[0])
else:
	print('-1')


import re
S = input()
m = re.search('([a-zA-Z0-9])\\1+', S)
if bool(m):
	print(m.group(1))
else:
	print(-1)


import re
m = re.search('([A-Za-z0-9])\\1{1,}', input())
if m:
	print(m.group(1))
else:
	print(-1)


from re import *
consecrep = search('([a-zA-Z0-9])\\1+', input().strip())
print(consecrep.group(1) if consecrep else -1)


import re
s = input()
m = re.search('([a-zA-Z0-9])\\1+', s)
if m:
	print(m.groups()[0])
else:
	print('-1')


import re
s = input()
g = re.findall('([A-Za-z0-9])(\\1)', s)
if len(g):
	print(g[0][0])
else:
	print(-1)


import re
m = re.search('([a-zA-Z0-9])\\1+', input().strip())
print(m.group(1) if m else '-1')


import re
m = re.search('([a-zA-Z0-9])\\1', input())
if m:
	print(m.group(1))
else:
	print(-1)


import re
theInput = input()
m = re.search('(?P<char>[a-zA-Z0-9])\\1', theInput)
if bool(m):
	print(m.groupdict()['char'])
else:
	print(-1)


import re
line = input()
m = re.search('([a-zA-Z0-9])\\1', line)
if m:
	print(m.groups()[0])
else:
	print(-1)


import re
s = input()
l = [match[0] for match in re.findall('(([a-zA-Z0-9])\\2{1,})', s)]
if len(l) > 0:
	print(l[0][0])
else:
	print(-1)


import re
m = re.search('([a-zA-Z0-9])\\1+', input().strip())
print(m.group(1) if m else -1)


import re
m = re.search('([a-zA-Z0-9])((.*\\1\\1)|(\\1))', input().strip())
if m != None:
	print(m.group(1))
else:
	print('-1')


import re

def __starting_point():
	string = input()
	match = re.search('([a-zA-Z0-9])\\1+', string)
	print(match.group(1) if match else -1)
__starting_point()


import re
s = input().strip()
if re.search('([a-zA-Z0-9])\\1+', s) == None:
	print('-1')
else:
	print(re.search('([a-zA-Z0-9])\\1+', s).group()[0])


import re
m = re.search('([A-Za-z0-9])\\1', input())
print(m.group(1) if m else -1)


import re
m = re.search('(?!_)(\\d|\\w)\\1', input())
if m is not None:
	print(m.group(0)[0])
else:
	print(-1)


import re
s = input().strip()
for i in range(len(s) - 1):
	if re.match('[a-zA-Z0-9]', s[i]) and s[i] == s[i + 1]:
		print(s[i])
		exit()
print(-1)


import re
r = re.search('(\\w(?!_))\\1+', input().strip())
print(r.group(1) if r else -1)


import re
no = input()
siz = len(no)
flag = True
for i in range(siz - 1):
	if no[i].isalnum() and no[i] == no[i + 1]:
		print(no[i])
		flag = False
		break
if flag:
	print('-1')


import re
S = input()
m = re.search('(?P<prevChar>[a-zA-Z0-9])(?P=prevChar)', S)
if m is None:
	print(-1)
else:
	print(m.group(0)[0])


import re
stri = input()
a = re.search('([a-zA-Z0-9])\\1+', stri)
if a:
	print(a.group(1))
else:
	print(-1)


import re
alnum = re.search('(?P<alnum>\\d|[a-zA-Z])(?P=alnum)', input().strip())
if alnum == None:
	print('-1')
	exit()
groupie = alnum.groups()
print(groupie[0][0])


import re
match = re.search('([0-9A-Za-z])(?=\\1)', input())
if bool(match):
	print(match.group(0))
else:
	print(-1)


import re
pattern = re.compile('([a-zA-Z0-9])\\1{1,}')
match = pattern.search(input())
if match is None:
	print(-1)
else:
	print(match.group(0)[0])


import re

def main(a):
	ra = re.findall('[a-zA-Z0-9]+', a)
	strs = ''.join(ra)
	if ra == None:
		return -1
	else:
		for i in range(len(strs) - 1):
			if strs[i] == strs[i + 1]:
				return strs[i]
	return -1
a = input()
print(main(a))


import re
p = '([0-9a-zA-Z])\\1'
m = re.search(p, input())
if m:
	print(m.group(0)[0])
else:
	print(-1)


import re
m = re.search('([a-zA-Z0-9])\\1', input())
if m != None:
	print(m.group(1))
else:
	print(-1)


import re
Crit = re.compile('([a-zA-Z0-9])\\1+')
result = Crit.search(input())
print(result.group(1) if result else -1)


import re
s = input()
res = re.search('([A-Za-z0-9])\\1', s)
if res == None:
	print(-1)
else:
	print(res.group(1))


import re
import sys
MATCH_REGEX = '([a-zA-Z0-9])\\1'
S = sys.stdin.readline().strip()
m = re.search(MATCH_REGEX, S)
print(m.group(1) if m else -1)


import sys
import re

def vn():
	s = sys.stdin.readline()
	c = re.search('((?P<a>[a-zA-Z0-9])(?P=a))|((?P<c>[a-zA-Z0-9]).*(?P=c){2,})', s)
	if c:
		print(c.group(0)[0])
		return
	print(-1)
	return

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


import re
reg = '([A-Za-z0-9])\\1{1,}'
s = input().strip()
r = re.findall(reg, s)
if r:
	print(r[0])
else:
	print(-1)


import re
m = re.search('([A-Za-z0-9])\\1+', input())
print(m.group(0)[0] if m else -1)


import re
s = input()
match = re.search('([a-zA-Z0-9])\\1', s)
if match:
	print(match.group(1))
else:
	print('-1')


import re
pattern = re.compile('([a-zA-Z0-9]+)\\s*\\1')
a_str = input()
m = re.search(pattern, a_str)
print(m.group(1) if m else -1)


import re

def main():
	s = input()
	m = re.search('([a-z0-9])\\1{1}', s)
	print(s[m.start()] if m else -1)
main()


import re
m = re.search('([a-zA-Z0-9])\\1', input())
print(m.group(1) if m else -1)


import re
l = re.findall('([A-Za-z0-9])\\1+', input())
if len(l) > 0:
	print(l[0])
else:
	print('-1')


import re
m = re.search('([a-z0-9A-Z])\\1', input())
print(m.group(1) if m else -1)


import re
result = re.search('([0-9a-zA-Z])\\1', input())
if result:
	print(result.group(1))
else:
	print(-1)


import re
m = re.search('([a-zA-Z1-9])\\1{1,}', input())
print(m.group(1) if m else -1)


import re
S = input()
m = re.search('([a-zA-Z0-9])\\1+', S)
if m:
	print(m.group(1))
else:
	print(-1)


import re
s = re.search('([A-Za-z0-9])\\1+', input().strip())
print(s.group(1) if s else -1)


import re
search = re.search('(([A-Za-z0-9])\\2)', str(input()))
if search is not None:
	print(search.group(2))
else:
	print('-1')


import re
a = input()
m = re.search('([a-zA-Z0-9])\\1+', a)
print(m.group(1) if m else -1)


import re
t = re.search('([a-zA-Z0-9])\\1', input())
if t:
	print(t.group(1))
else:
	print(-1)


import re
m = re.search('([a-zA-Z0-9])\\1+', input().strip())
print(m.group(1) if m != None else -1)


import re
S = input()
m = re.search('([a-zA-Z0-9])\\1', S)
print(m.group(1)) if m else print(-1)


import re
m = re.search('([a-zA-Z0-9])\\1+', input())
print(m.group(1) if m else -1)


import re
E = re.compile('([a-zA-Z0-9])\\1+')
S = input().strip()
m = re.search(E, S)
if m == None:
	print(-1)
else:
	print(m.groups(1)[0])


import re
result = re.search('([0-9A-Za-z])\\1{1,}', input())
print(result.group(1) if result else '-1')


import re
m = re.search('([0-9a-zA-Z])\\1', input())
if bool(m):
	print(*m.groups())
else:
	print(-1)


import re
a = input()
b = ''
for i in a:
	if i.isalnum():
		b += i
bu = re.search('(\\w)\\1\\1*', b)
if bu:
	print(bu.group(1))
else:
	print(-1)


import re
ret = -1
l = list((it.group(1) for it in re.finditer('(.)\\1+', input()) if it.group(1).isalnum()))
if len(l):
	ret = l[0]
print(ret)


import re
s = str(input())
r = re.search('([0-9a-zA-Z])\\1+', s)
print(r.groups()[0] if r else -1)


import re
x = input()
m = re.search('([a-zA-Z0-9])\\1{1,}', x)
if m is None:
	print('-1')
else:
	print(m.groups()[0])


import re
m = re.match('.*?([0-9a-zA-Z])\\1+.*', input())
if bool(m):
	print(m.group(1))
else:
	print(-1)


def twin(ls):
	val = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
	xs = list(ls.strip())
	(i, end) = (0, len(xs) - 1)
	test = False
	while i < end and (not test):
		if xs[i] in val:
			test = xs[i] == xs[i + 1]
			if not test:
				i += 1
		else:
			i += 1
	print(xs[i]) if test else print(-1)
twin(input())


import re
m = re.search('([A-Za-z0-9])\\1{1,}', input())
print(m.group(1) if m else '-1')


import re
m = re.search('([a-zA-Z0-9])\\1{1,}', input())
if m is not None:
	print(m.group(1))
else:
	print(-1)


import re
r = re.search('([0-9a-zA-Z])\\1', input())
l = r.group()[0] if r != None else None
print(l if l != None else -1)


import re
m = re.search('([\\da-zA-Z])\\1', input())
print(m.group(1) if m else -1)


import re
m = re.match('.*?([0-9A-Za-z])\\1', input().strip())
print(m.group(1) if m else -1)


import re
m = re.search('([A-Za-z0-9])\\1+', input())
print(m.group(0)[0] if m is not None else -1)


import re
S = input()
result = re.search('([a-z0-9A-Z])\\1', S)
if result:
	print(result.group(0)[0])
else:
	print(-1)


import re
m = re.search('(?P<repeated>[0-9a-zA-Z])(?P=repeated)', input())
if m:
	print(m.group('repeated'))
else:
	print(-1)


import re
my_string = input().strip()
my_new_string = ''
done = 0
for i in range(len(my_string) - 1):
	candidate = my_string[i:i + 2]
	if candidate[0] == candidate[1]:
		if bool(re.match('([a-zA-Z0-9])([a-zA-Z0-9])', candidate)):
			print(candidate[0])
			done = 1
			break
if done == 0:
	print(-1)


import re
s = input().strip()
repeating = re.search('([A-Za-z0-9])\\1{1,}', s)
print(repeating.group()[0] if repeating else -1)


import re
try:
	l = list(re.search('([a-zA-Z0-9])\\1+', input().strip()).group(0)[0])
	if l:
		print(l[0])
	else:
		print('-1')
except Exception:
	print('-1')


import re
l = re.search('([0-9a-zA-Z])\\1+', input().strip())
print(l.group(1) if l else '-1')


import re
m = re.match('.*?([a-z0-9])\\1', input())
if m:
	print(m.group(1))
else:
	print(-1)


import re
m = re.match('.*?(?P<first>[0-9a-zA-Z])(?P=first)', input().rstrip())
print('-1' if m == None else m.groupdict()['first'])


import re
S = input()
m = re.search('([A-Za-z0-9])\\1{1,}', S)
if bool(m) == True:
	print(S[m.start()])
else:
	print(-1)


import sys, re
string = str(input().strip())
if not re.search('([A-Za-z0-9])\\1', string):
	print(-1)
else:
	m = re.search('([A-Za-z0-9])\\1', string).group()
	print(m[0])


import re
idx = re.search('([a-zA-Z0-9])\\1+', input())
if idx:
	print(idx.group(0)[0])
else:
	print('-1')


import re
pattern = '([a-zA-Z0-9])\\1{1,}'
m = re.search(pattern, input())
if m:
	print(m.groups()[0])
else:
	print('-1')


import re
s = input().strip()
match = re.search('([a-zA-Z0-9])\\1+', s)
if match:
	print(match.group(1))
else:
	print(-1)


import re
g = re.match('.*?([a-zA-Z0-9])\\1+', input())
if g and g.groups(1):
	print(g.groups(1)[0])
else:
	print(-1)


import re
m = re.search('([^\\W_])\\1', input())
if m:
	print(''.join(m.groups()))
else:
	print(-1)


import string
valid = set(string.ascii_letters + string.digits)
s = input()
found = False
for i in range(1, len(s)):
	if s[i] in valid and s[i] == s[i - 1]:
		found = True
		print(s[i])
		break
if not found:
	print(-1)


import re
m = re.search('([A-Za-z0-9])\\1', input().strip())
print(m.group(0)[0] if m else '-1')


import re
m = re.match('.*?([0-9a-zA-Z])\\1', input())
print(m.group(1) if m else -1)


import re
S = input()
m = re.match('.*?([0-9A-Za-z])\\1', S)
if bool(m):
	print(m.group(1))
else:
	print(-1)