Python @ DjangoSpin

PyPro #97 Find all words with length of 4 characters

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon
Reading Time: 1 minutes

Find all words with length of 4 characters in Python

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.


See also:

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon

Leave a Reply