---
title: "Pattern Matching in Erlang"  
description: "pattern matching is a process of checking a given sequence of tokens for the presence of the constituents of some pattern . Erlang uses pattern matchi"  
author: "Sunil Singh"  
published: 2015-09-14  
updated: 2018-03-27  
canonical: https://www.mindstick.com/articles/1865/pattern-matching-in-erlang  
category: "erlang"  
tags: ["erlang"]  
reading_time: 1 minute  

---

# Pattern Matching in Erlang

[Pattern matching](https://www.mindstick.com/forum/160352/how-to-use-regex-in-javascript-for-pattern-matching) is a [process](https://www.mindstick.com/forum/23018/how-can-i-create-a-process) of checking a given [sequence](https://www.mindstick.com/interview/34504/difference-between-identity-vs-sequence) of tokens for the [presence](https://www.mindstick.com/articles/12492/how-to-enhance-your-presence-on-facebook) of the constituents of some pattern . Erlang uses pattern matching to bind [variables](https://www.mindstick.com/articles/715/php-variables) to values. In erlang pattern matching can be explicit [as well as](https://www.mindstick.com/forum/156547/difference-between-max-width-and-width-as-well-as-max-height-and-height) [implicit](https://www.mindstick.com/interview/827/what-are-implicit-objects-list-them) .\

##### Explicit pattern matching example is given below-

\

```
Num = 10,[Num1,Num2,Num3,Num4] = [1,2,3,4],[P1,P2|P3] = [1,2,3,4,5,6,7],
```

In the above example Num=10 is explicit pattern matching Value 10 is assigned to Num we can not re-assign different value to erlang variables,one time [assignment](https://www.mindstick.com/articles/126300/apa-citation-style-get-to-know-about-it-for-your-next-assignment) is allowed.In the second line Num1,Num2,Num3 and Num4 have values 1,2 and so on,this is explicit pattern matching. P1 have value 1,P2 have value 2 and P have values [3,4,5,6,7].Implicit pattern matching occurred in [function](https://www.mindstick.com/articles/43970/purchase-suitable-wedding-dresses-for-your-wedding-function) calls.\

##### Guard Patterns matching is given below-

\

```
erlang_pattern_matching(A) ->Speak = if A == cat  -> "meow";A == frog  -> "croak";A == dog  -> "bark";A == bee  -> "buzz";A==elephant->"trumpet";A==snake->"hiss";A==sheep->"bleat";A==lion ->"roar";A==swan->"cry";	true -> "animal not exist in pattern"end,{A, "says " ++ Speak ++ "!"}.
```

---

Original Source: https://www.mindstick.com/articles/1865/pattern-matching-in-erlang

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
