You can try below solution, here I haven't imported any module. The only functions used are strip, split and replace
input_string = "(Hello|Hi) my name is (Bob|Robert)"
split_string = (input_string.replace("("," ").replace(")"," ")).split(" ")
print ([i.strip().split("|") for i in split_string])
#Output --> [['Hello', 'Hi'], ['my name is'], ['Bob', 'Robert']]
I hope this helps!
If you need the final solution to your query then use below code:
from itertools import product
input_string = "(Hello|Hi) my name is (Bob|Robert)"
split_string = (input_string.replace("("," ").replace(")"," ")).split(" ")
jj = [i.strip().split("|") for i in split_string]
kk = list(product(*jj))
print ([" ".join(i) for i in kk])
#output --> ['Hello my name is Bob', 'Hello my name is Robert', 'Hi my name is Bob', 'Hi my name is Robert']
The above code will also work for: input_string = "(Hello|Hi|Hey) my (name|naam) is (Bob|Robert)"