Python Forum

Full Version: How can I find all combinations with a regular expression?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Python 3.9.5

I wrote the following code:
pattern_space = '[\s]+'
pattern_name= '(.{4,})'
pattern =  pattern_name + pattern_space + '(street|town){1}' + pattern_space + pattern_name
result = re.search(pattern, 'Boston town street Coco')
And I got:
Output:
Boston town street Coco
I also want to get a valid variant:
Output:
Boston town street Coco
How can I get ALL the possible variants?