# @parameter1/build-match-regex

> Builds regular expressions for matching parts of phrases to values.

Latest version **2.0.0** (published 2022-01-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @parameter1/build-match-regex
pnpm add @parameter1/build-match-regex
yarn add @parameter1/build-match-regex
bun add @parameter1/build-match-regex
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2022-01-20 |
| First published | 2020-10-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=14.0 |
| Dependencies | 1 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Jacob Bare |
| Maintainers | zarathustra323, solocommand |

## Links

- npm: https://www.npmjs.com/package/@parameter1/build-match-regex
- Repository: https://github.com/parameter1/libraries
- Homepage: https://github.com/parameter1/libraries/tree/master/packages/build-match-regex#readme
- Issues: https://github.com/parameter1/libraries/issues
- npm.io page: https://npm.io/package/@parameter1/build-match-regex

## Dependencies (1)

- [escape-string-regexp](https://npm.io/package/escape-string-regexp.md) ^5.0.0

## Recent versions

- 2.0.0 (latest) — 2022-01-20
- 1.0.16 — 2021-09-10
- 1.0.15 — 2021-08-04
- 1.0.14 — 2021-07-08
- 1.0.13 — 2021-06-29
- 1.0.12 — 2021-05-25
- 1.0.11 — 2021-05-11
- 1.0.10 — 2021-05-11
- 1.0.9 — 2021-04-30
- 1.0.8 — 2021-03-31
- 1.0.7 — 2021-03-16
- 1.0.6 — 2021-02-15
- 1.0.5 — 2021-01-23
- 1.0.4 — 2021-01-07
- 1.0.3 — 2020-12-08
- … 3 more at https://npm.io/package/@parameter1/build-match-regex/versions

## README

# Build Match Regex
Builds regular expressions for matching parts of a phrase to a value. Useful for autocompleters, typeaheads, or quasi-search functions.

## Installation
```
yarn add @parameter1/build-match-regex
```

## Usage
```js
import buildMatchRegex from '@parameter1/build-match-regex';

const phrase = 'quick brown fox';
const regex = buildMatchRegex({
  phrase,
  // can be one of 'starts', 'ends', 'exact', or 'contains'
  position: 'contains', // default
  // can be either 'all' or 'any'
  words: 'all', // default
  insensitive: true, // default, set to false to force case-sensitivity
});

regex.test('brown fox'); // false
regex.test('brown fox quick'); // true
regex.test('Quickest Brownest Fox!'); // true
```

### Options

Assuming a phrase of `quick brown fox`...

Position `starts`:
 - Words: `any`
   - Where a value starts with `quick`, `brown`, or `fox`
   - `/^quick|^brown|^fox/i`
 - Words: `all`
   - Where a value literally starts with `quick brown fox`
   - `/^quick brown fox/i`

Position `ends`:
 - Words: `any`
   - Where a value ends with `quick`, `brown`, or `fox`
   - `/quick$|brown$|fox$/i`
 - Words: `all`
   - Where a value literally ends with `quick brown fox`
   - `/quick brown fox$/i`

Position: `exact`:
 - Words: `any`
   - Where a value exactly matches `quick`, `brown`, or `fox`
   - `/^quick$|^brown$|^fox$/i`
 - Words: `all`
   - Where a value exactly matches `quick brown fox`
   - `/^quick brown fox$/i`

Position `contains`:
 - Words: `any`
   - Where a value contains any partial matches of `quick`, `brown`, or `fox`
   - `/quick|brown|fox/i`
 - Words: `all`
   - Where a value contains all partial matches of `quick`, `brown`, and `fox`
   - `/(?=.*quick)(?=.*brown)(?=.*fox)/i`

---
_Source: https://npm.io/package/@parameter1/build-match-regex · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
