It seems to me that there are these implicit questions in your post:

What is the pattern to match a pattern-definition, exactly as it is written?

How can I test if a given pattern intersects with, or is a subset of another pattern?

The second, the heart of your question I believe, is both good and challenging.

*I shall answer the first one now, with the hope of answering the second one at a later time.*

## Point 1: Matching an explicit pattern

The function `Verbatim`

tells *Mathematica* to match the enclosed code itself rather than using it as a pattern definition. Example:

```
Cases[{1, 2, _, _, 5}, Verbatim[_]]
```

```
{_, _}
```

There is a related function that bears mentioning in this context: `HoldPattern`

. This is somewhat similar to `Verbatim`

but instead of telling *Mathematica* to not use the enclosed expression as a pattern, it tells *Mathematica* not to evaluate the expression.

```
{a, b, c} = {3, 4, 5};
Cases[Hold[1, 2, a, b, c], HoldPattern[b]]
```

```
{4}
```

On the other hand `Verbatim`

evaluates its contents:

```
pat = _ ;
Cases[{1, 2, _, _, 5}, Verbatim[pat]]
```

```
{_, _}
```

These functions can be used on parts of an expression, not merely on a complete expression. To use these effectively you must become familiar with the `FullForm`

of pattern expressions. Suppose we want to match expressions such as `x_`

or `y_`

. The expression `x_`

can be written `Pattern[x, _]`

but if we try to match the pattern `Pattern[_, _]`

we get an error because `Pattern`

tries to evaluate. We can use either `HoldPattern`

or `Verbatim`

to prevent this, the latter because `Pattern`

by itself does not evaluate:

```
Cases[{1, 2, x_, y_, 5}, HoldPattern[Pattern][_, _]]
Cases[{1, 2, x_, y_, 5}, Verbatim[Pattern][_, _]]
```

```
{x_, y_}
{x_, y_}
```

It is not clear from the example above, but these patterns also match `q__`

, `r_Real`

, `s___`

because these are also of the form `Pattern[name, type]`

:

```
Cases[{1, 2, x_, q__, r_Real, s___, 5}, HoldPattern[Pattern][_, _]]
```

```
{x_, q__, r_Real, s___}
```

If we want *only* expressions of the form `name_`

then we need to be more specific. We need `Verbatim`

because it is not an issue of evaluation but rather one of recognition as a pattern construct.

```
Cases[{1, 2, x_, q__, r_Real, s___, 5}, HoldPattern[Pattern][_, Verbatim[_]]]
```

```
{x_}
```

Nice classification of the problem, I definitely aimed for the second one. I think it would be reasonable to split my original question, and this thread could be for the first problem (

`Verbatim`

) while I pose a new question to answer the second. Should I do it, or should I just clarify this one? – István Zachar – 2012-03-13T11:15:29.863@IstvánZachar I favor your posting a new question. None of the answers here

reallyaddress that, and a new question will get more attention. I think it is a very interesting question and I intend to spend some time on it in the next few days, assuming that it is not quickly solved in a robust way by someone else. Please be quite specific regarding the behavior(s) that you want as I foresee defining those behaviors as a major aspect of the problem. Also, I think there will be unavoidable ambiguity in places, and it would be good to at least address how these should be approached. – Mr.Wizard – 2012-03-13T13:15:51.2571

I've split the question. If you plan to post an answer for problem #2, please do it under the other one, here.

– István Zachar – 2012-03-14T01:26:12.143