Reading Time: 1 minutes
Find all words with length of 4 characters in Python
Write a Regular Expression in Python to find all words with length of 4 characters in a string.
import re sourceString = 'two three four five six seven' print( re.findall(r'\b\w{4}\b', sourceString) ) # ['four', 'five']
To learn more about Regular Expressions in Python, click here.