Expand Python regex to list of all possible strings [closed]

2024/11/24 8:38:00

I am new to Python and not a full time coder as well. I am trying to see if there are any inbuilt regex functions in python that will provide the entire (expanded) list of strings from a python regex.

Example: for the input:

Good (Morning|afternoon|evening) my (friends|family|brothers|sisters). hope you like (apple|orange|grape) juice

The outputs should be:

Good Morning my friends. hope you like apple juice
Good Morning my friends. hope you like orange juice
Good Morning my friends. hope you like grape juice
Good Morning my family. hope you like apple juice
Good Morning my family. hope you like orange juice
Good Morning my family. hope you like grape juice
Good Morning my brothers. hope you like apple juice
Good Morning my brothers. hope you like orange juice
Good Morning my brothers. hope you like grape juice
Good Morning my sisters. hope you like apple juice
Good Morning my sisters. hope you like orange juice
Good Morning my sisters. hope you like grape juice
Good afternoon my friends. hope you like apple juice
Good afternoon my friends. hope you like orange juice
Good afternoon my friends. hope you like grape juice
Good afternoon my family. hope you like apple juice
Good afternoon my family. hope you like orange juice
Good afternoon my family. hope you like grape juice
Good afternoon my brothers. hope you like apple juice
Good afternoon my brothers. hope you like orange juice
Good afternoon my brothers. hope you like grape juice
Good afternoon my sisters. hope you like apple juice
Good afternoon my sisters. hope you like orange juice
Good afternoon my sisters. hope you like grape juice
Good evening my friends. hope you like apple juice
Good evening my friends. hope you like orange juice
Good evening my friends. hope you like grape juice
Good evening my family. hope you like apple juice
Good evening my family. hope you like orange juice
Good evening my family. hope you like grape juice
Good evening my brothers. hope you like apple juice
Good evening my brothers. hope you like orange juice
Good evening my brothers. hope you like grape juice
Good evening my sisters. hope you like apple juice
Good evening my sisters. hope you like orange juice
Good evening my sisters. hope you like grape juice

It doesn't matter in which order it is populated. As long as I have the output in a list, that's ok.

Answer

You could use Exrex. Install with pip install exrex.

Then execute in terminal:

exrex 'Good (Morning|afternoon|evening) my (friends|family|brothers|sisters)\. hope you like (apple|orange|grape) juice\.'

Make sure not to forget the backslashes \ before the dots ., as dots are a special character inside regexes. This will return:

Good Morning my friends. hope you like apple juice.
Good Morning my friends. hope you like orange juice.
Good Morning my friends. hope you like grape juice.
Good Morning my family. hope you like apple juice.
Good Morning my family. hope you like orange juice.
Good Morning my family. hope you like grape juice.
Good Morning my brothers. hope you like apple juice.
Good Morning my brothers. hope you like orange juice.
Good Morning my brothers. hope you like grape juice.
Good Morning my sisters. hope you like apple juice.
Good Morning my sisters. hope you like orange juice.
Good Morning my sisters. hope you like grape juice.
Good afternoon my friends. hope you like apple juice.
Good afternoon my friends. hope you like orange juice.
Good afternoon my friends. hope you like grape juice.
Good afternoon my family. hope you like apple juice.
Good afternoon my family. hope you like orange juice.
Good afternoon my family. hope you like grape juice.
Good afternoon my brothers. hope you like apple juice.
Good afternoon my brothers. hope you like orange juice.
Good afternoon my brothers. hope you like grape juice.
Good afternoon my sisters. hope you like apple juice.
Good afternoon my sisters. hope you like orange juice.
Good afternoon my sisters. hope you like grape juice.
Good evening my friends. hope you like apple juice.
Good evening my friends. hope you like orange juice.
Good evening my friends. hope you like grape juice.
Good evening my family. hope you like apple juice.
Good evening my family. hope you like orange juice.
Good evening my family. hope you like grape juice.
Good evening my brothers. hope you like apple juice.
Good evening my brothers. hope you like orange juice.
Good evening my brothers. hope you like grape juice.
Good evening my sisters. hope you like apple juice.
Good evening my sisters. hope you like orange juice.
Good evening my sisters. hope you like grape juice.
https://en.xdnf.cn/q/120559.html

Related Q&A

How can I group and sum a pandas dataframe? [duplicate]

This question already has answers here:How do I Pandas group-by to get sum?(11 answers)Closed 1 year ago.Ive had a good hunt for some time and cant find a solution so asking here. I have data like so:…

python add value to a list when iterate the list

values = [2,3,4] for v in values:values.append([v,255,255])Why do the statements above never end? I make a mistake in my code. However, I find it will never stop when I execute the code above.

resizing images from 64x64 to 224x224 for the VGG model

Can we resize an image from 64x64 to 256x256 without affecting the resolution is that a way to add zero on new row and column in the new resized output I m working on vgg and I get an error while addin…

Python slicing explained [duplicate]

This question already has answers here:How slicing in Python works(38 answers)Closed 6 years ago.OK I understand the basics, but can someone explain code copied from Gregs answer here:a[1::-1] # the …

Comparison between string characters within a list [duplicate]

This question already has an answer here:How to compare characters of strings that are elements of a list? [duplicate](1 answer)Closed 2 years ago.Having a Python list, containing same length strings,…

Pyspark filling missing dates by group and filling previous values

Spark version 3.0. I have two dataframes. I create one dataframe with date columns using pandas date range. I have a 2nd spark dataframe contains the company name, dates and value. I want to merge the …

How to loop in the opposite order?

I am a beginner programmer. Here is my code:n = int(input()) from math import* for i in range(n):print(n, "\t", log10(n))i = i + 1n = n - 1Its output is:10 1.0 9 0.9542425094393249 8 …

Override methods with same name in Python programming [duplicate]

This question already has answers here:Closed 12 years ago.Possible Duplicate: How do I use method overloading in Python?I am new to Python programming, and I like to write multiple methods with the …

TypeError: function object is not subscriptable in Python 3.4.3?

I have a food menu and the stock and prices are in separate dictionaries.Food Stock:Food_Stock = {Chips : 15,Bagels : 27,Cookies : 25}#Food Stock.Food Prices:Food_Prices = {#Food Prices.Chips : 1,Bagel…

Insert a value in date format dd-mm-yyyy in dictionary in python

I am creating a dictionary having some values including a date of birth of a person. But when I run my code, it is giving an error "datetime.datetime has no attribute datetime" . Here is my …