Given a function with several arguments
I would like to extract all arguments with the head
g2 as a list. So the output I am looking for is
The way I used to extract one head, say
g1, is simply using the rule
However, with two heads, this method does not work. I could write a module to do that but I wonder if there is a simpler way like the above rule for one head. Thank you so much!