UPDATED
This question is about: "What is the pattern to match a pattern-definition, exactly as it is written?"
My original question is now split according to Mr.Wizards insightful answer below. This question is about simple cases which can be solved with Verbatim
. The other question (here) is what I should have asked originally: how to generally match and unify patterns and how to find their most general unifier. Therefore the following examples contain cases for both this and the other question. I won't modify these as it would ruin the understandability of the answers.
Consider the following pattern comparisons, which intuitively suggest a matching, though all returning False
:
MatchQ[a | b, b | a]
MatchQ[{a ..}, {a ..}]
MatchQ[{a ..}, {a ...}]
The output I would like to have is True
. The idea is that the first argument specifies an object that can either be a
or b
. I scan through a lot of these objects looking for those that can stand in for either a
or b
, see toy example:
rules = {a -> 1, b -> 2, c -> 3, a | b -> 4, c | d -> 5, d | b | c -> 6};
Cases[rules, _?(MatchQ[First@#, a | b] &)]
{a -> 1, b -> 2}
Instead, I need the output to be:
{a -> 1, b -> 2, a | b -> 4, d | b | c -> 6}