Reading Time: 1 minutes
Match three-of-a-kind characters from a string in Python
Write a Regular Expression in Python to match three-of-a-kind characters from a string containing characters other than a newline e.g. 'abc123abc123abc'.
Match three-of-a-kind characters from a string
import re sourceString = 'abc123abc123abc' matchObject = re.search(r'.*?(.).*?\1.*?\1', sourceString) print( matchObject.groups() ) # ('a',)
For clarity, try it out on Regex101. To learn more about Regular Expressions in Python, click here.