Group(), Groups() & Groupdict() - Hacker Rank Solution
[A-Za-z0-9])\1+ can be used to solve this problem.
The expression
The expression
The expression
([A-Za-z0-9])
will match an alphanumeric character and store it in group .The expression
\1
matches the exact same text that was matched by the first capturing group.import re m = re.search(r'([A-Za-z0-9])\1+',raw_input()) if m: print m.group(1) else: print -1
this isnt working...please update
ReplyDeleteimport re
ReplyDeletem = re.search(r'([a-zA-Z0-9])\1+', input().strip())
print(m.group(1) if m else -1)
#To work in python 3
ReplyDeleteimport re
m = re.search(r'([A-Za-z0-9])\1+',input())
if m:
print(m.group(1))
else:
print(-1)