Python Forum
How can I find all combinations with a regular expression?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I find all combinations with a regular expression?
#1
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Regular Expression search to comment lines of code Gman2233 5 243 Sep-08-2022, 06:57 AM
Last Post: ndc85430
  List Creation and Position of Continue Statement In Regular Expression Code new_coder_231013 3 587 Jun-15-2022, 12:00 PM
Last Post: new_coder_231013
  Need help with my code (regular expression) shailc 5 730 Apr-04-2022, 07:34 PM
Last Post: shailc
  Regular Expression for matching words xinyulon 1 1,147 Mar-09-2022, 10:34 PM
Last Post: snippsat
  regular expression question Skaperen 4 1,486 Aug-23-2021, 06:01 PM
Last Post: Skaperen
  Python Regular expression, small sample works but not on file Acernz 5 1,551 Jun-09-2021, 08:27 PM
Last Post: bowlofred
  Regular expression: cannot find 1st number in a string Pavel_47 2 1,582 Jan-15-2021, 04:39 PM
Last Post: bowlofred
  Regular expression: return string, not list Pavel_47 3 1,647 Jan-14-2021, 11:49 AM
Last Post: Pavel_47
  All possible combinations CODEP 2 1,249 Dec-01-2020, 06:10 PM
Last Post: deanhystad
  Triplet Combinations of All Values quest 2 1,253 Nov-05-2020, 09:22 AM
Last Post: quest

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020