I have a list of expressions which are multiplications of different types of objects. The question is broadly about how I can look for a pattern an exact number of times and exclude patterns from the search.
I will start with an example list on which I am going to base my question:
lyst = {n1 * n2 * Pair[M[p1],M[s2]] * Pair[M[p3],M[s4]], n3 * n4 * Pair[M[p1],M[s2]] * Pair[M[p1],M[s2]], n5 * n6 * Pair[M[p1],M[s2]] }
Here, n1 - n4 are numbers and "Pair" and "M" are Heads that are defined in my program. Now what I would like to do is select all elements, in which the expression Pair[M[p1],M[s2]] appears exactly N times without objects whose head is 'Pair' appearing again (subsequently I also want to do this with other expressions but this is just to understand how I should tackle this problem).
Example: I would like to have a pattern test that looks for all elements in 'lyst' which contain Pair[M[p1],M[s2]] without the structure Pair[....] appearing again. In my example list that would just be the last element only, since it does contain this expression and 'Pair[...]' does not occur again.
I would be very thankful for suggestions on how to do this since I do not really have a good idea so far.