Reading Time: 1 minutesMatch three-of-a-kind characters from a string in Python
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
sourceString = 'abc123abc123abc' |
matchObject = re.search(r '.*?(.).*?\1.*?\1' , sourceString) |
print ( matchObject.groups() ) |
For clarity, try it out on Regex101. To learn more about Regular Expressions in Python, click here.
See also: