# fluent-regex

> A simple, type-safe, fluent api to construct regular expressions (and no dependencies!)

Latest version **1.0.3** (published 2018-07-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install fluent-regex
pnpm add fluent-regex
yarn add fluent-regex
bun add fluent-regex
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2018-07-25 |
| First published | 2018-06-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 22.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Gilly Barr |
| Maintainers | gillyb |

## Links

- npm: https://www.npmjs.com/package/fluent-regex
- Homepage: https://github.com/gillyb/fluent-regex
- npm.io page: https://npm.io/package/fluent-regex

## Recent versions

- 1.0.3 (latest) — 2018-07-25
- 1.0.2 — 2018-06-13
- 1.0.1 — 2018-06-12
- 1.0.0 — 2018-06-10

## README

[![Build Status](https://travis-ci.org/gillyb/fluent-regex.svg?branch=master)](https://travis-ci.org/gillyb/fluent-regex)

# fluent-regex

This is a small, dependency-free library intended to help you construct regex statements in a fluent and typed way (instead of using cryptic symbols no one fully understands).  

Using Typescript is preferred when using this library since it can help you complete the "fluent-regex" syntax easily.  

Here are a few examples for you to see the syntax :  

**American phone number:**
```
// RegExp syntax
const r = /(\(\d{3}\)-)?\d{3}-\d{4}/g;

// fluent-regex syntax
const r = new RegexSequence(
  new RegexSequence('(', RegexLiteral.anyDigit().exactAmount(3), ')-').optional(),
  RegexLiteral.anyDigit().exactAmount(3),
  '-',
  RegexLiteral.anyDigit().exactAmount(4)
);
```

**Simple email validation:** *NOTE: This isn't a real valid email check according to the official spec, so don't use this as-is*
```
// RegExp syntax
const r = /(\d|[a-zA-Z]|\.|\+|\(|\)){2,}@(\d|[a-zA-Z]|\.|\+|\(|\)){2,}\.[a-zA-Z]{2,}(\.[a-zA-Z]{2,})?/;

// fluent-regex syntax
const r = new RegexSequence(
  Group.or(RegexLiteral.anyDigit(), RegexLiteral.anyLetter(), '.', '+', '(', ')').atLeastAmount(2),
  '@',
  Group.or(RegexLiteral.anyDigit(), RegexLiteral.anyLetter(), '.', '+', '(', ')').atLeastAmount(2),
  '.',
  RegexLiteral.anyLetter().atLeastAmount(2),
  new RegexSequence('.', RegexLiteral.anyLetter().atLeastAmount(2)).optional()
);
```

**Some very simple, other use cases:**  
```
// Searching for my first name, and optional last name
const regex = new RegExp('gilly( barr)?', 'i');
const fluentRegex = R.sequence('gilly', R.optional(' barr')).toRegex(RegexFlags.IGNORE_CASE);

// search for 3 digits in parentheses
const regex = /\(?[0-9]{3}\)?/;
const fluentRegex = R.sequence('(', RegexLiteral.anyDigit().exactAmount(3), ')');
```

# Installing  
```
npm install --save fluent-regex
```

# Running tests  
```
npm test
```

# Missing Features (_[Reference](https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference)_)  
* Matching unicode characters - '\P'
* Special anchors - (except for '^' & '$')
* 'Look ahead' groups
* 'Look behind' groups
* Match as few times as possible - '??'

# Contributing  
All contributions are welcome. Feel free to create a pull request or open an issue.  
If it's a pull request, please try to add some tests with it.  
**Every comment, issue or pull request will be addressed in a polite and friendly manner. :)**

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