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.
Group(), Groups() & Groupdict()
Group(), Groups() & Groupdict()
+ 0 comments import re m = re.match(r'.*?([^\W_])\1.*', input()) print(m.group(1) if m else -1)
+ 0 comments My solution in Python 3:
import re text = input() pattern = r'(\w(?!_))\1+' m = re.findall(pattern, text) print(m[0] if len(m)!=0 else -1)
With this solution we can keep a track on any 'nth' occurrence of the repeating character and can access it from list variable 'm' based on its index number.
+ 0 comments import re s = re.search(r"([a-zA-Z0-9])(\1)", input()) print(s.group(0)[0] if s else -1)
+ 1 comment 1.match = re.search(r'(\w)\1', s) 2.match = re.search(r'([a-zA-Z0-9])\1', s) Any idea why 1st is not a correct solution. since by definition: \w alphanumeric: [0-9a-zA-Z_] and includes "_" .
+ 0 comments import re pattern = re.compile(r'([a-zA-Z0-9])\1{1,}') match=re.search(pattern,input()) print(match.group(1) if match else -1)
Load more conversations
Sort 206 Discussions, By:
Please Login in order to post a comment