If Python supports conditionals:
For out of order stuff, just use a conditional.
Note - change the quantifier in the group to reflect how many items
are required to match. Below shows {2} which requires both items somewhere.
You could change it to {1,} - at least 1, or + - same thing.
(?:.*?(?:((?(1)(?!))aaa.*?bbb)|((?(2)(?!))bbb.*?aaa))){2}
Formatted:
(?:
.*?
(?:
( # (1)
(?(1)
(?!)
)
aaa .*? bbb
)
| ( # (2)
(?(2)
(?!)
)
bbb .*? aaa
)
)
){2}
Output:
** Grp 0 - ( pos 0 , len 21 )
aaa bbb bbb aaa
** Grp 1 - ( pos 0 , len 8 )
aaa bbb
** Grp 2 - ( pos 11 , len 10 )
bbb aaa