# Matching pattern algorithm

**URL:** <https://forum.kirupa.com/t/matching-pattern-algorithm/316782>\
**Category:** flash\
**Created:** [December 2, 2010, 8:56am UTC](https://forum.kirupa.com/t/matching-pattern-algorithm/316782 "2010-12-02T08:56:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Esseti](https://avatars.discourse-cdn.com/v4/letter/e/bb73d2/32.png) [@Esseti](https://forum.kirupa.com/u/Esseti)\
**Post date:** [December 2, 2010, 8:56am UTC](https://forum.kirupa.com/t/matching-pattern-algorithm/316782/1 "2010-12-02T08:56:03Z")

</div>

```auto

// So I've got an array consisting of unique, four digit String numbers (0,1,2 only).
var patterns:Array = ["1111", "2212", "1121", "2222", "1011", "2022", "2021", "1012", "1022", "2012", "1021", "2011", "0022", "0011", "0012", "0021"];

// And I want to match to them a variation of one of
// those elements which have shifted numbers by 1-3 places.
// Example: If I get a generated String number of '2221' I
// want to quickly match it to patterns[1], because it's a
// variation of that pattern, and return the +/- shifted places
// it represents.
// Example 2:
// Search value: '0111'
// Correct pattern: patterns[4], shifted:-1
// Example 3:
// Search value: '2200'
// Correct pattern: patterns[13], shifted:+2
// etc.

```

Is there a way to do this with RegExp maybe? I know that I could just add each variation of each pattern to the array, and just search it, but I want to do it more intelligently.
