Use this tag for questions about testing whether a data structure has a particular shape or contains particular values in certain locations. Many functional languages provide pattern matching constructs. Most questions in this tag should also have the tag for the language you are programming in. DO NOT USE THIS TAG FOR REGULAR EXPRESSION QUESTIONS, USE [regex] INSTEAD; similarly, for pattern matching (globbing) in POSIX-like shells, use [glob].
What is pattern matching?
Pattern matching means checking whether a data structure conforms to a certain pattern. In the abstract, a pattern can be any set of values; however most languages restrict patterns to expressing structural constraints, such as “all lists with at least two elements” or “all 2x2 matrices where the elements at (1,0) and (0,1) are equal”.
Languages such as ML, Haskell, Erlang and Mathematica have core language constructs for pattern matching. Other languages such as Lisp have derived pattern matching constructs.
Pattern-matching enhances a language in two directions: expressiveness, as complex sequences of tests can be written concisely, and performance, as the compiler is able (at least when pattern-matching is a core language construct) to optimize such constructs to generate the optimal number of tests (i.e. never checking twice the same condition).
Tag usage guidance
Regular expressions are an important special case of pattern matching on strings. Do not use the pattern-matching tag for regular expression questions, use the regex tag instead.
Pattern matching is normally exact. If you're looking for approximate patterns, for example in image or speech analysis, look for “recognition” rather than “matching”, for example pattern-recognition.