# @forensic-js/regex

> A module that builds on the existing RegExp module, making it easier working with text matching and replacement both in the browser and node environments

Latest version **1.0.2** (published 2019-05-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @forensic-js/regex
pnpm add @forensic-js/regex
yarn add @forensic-js/regex
bun add @forensic-js/regex
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-05-27 |
| First published | 2019-04-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 38.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Harrison Ifeanyichukwu |
| Maintainers | harrison-ifeanyichukwu |
| Keywords | regex, replace, replace-callback, placeholder-replacement, pattern-matching |

## Links

- npm: https://www.npmjs.com/package/@forensic-js/regex
- Repository: https://github.com/harrison-ifeanyichukwu/regex
- Homepage: https://github.com/harrison-ifeanyichukwu/regex#readme
- Issues: https://github.com/harrison-ifeanyichukwu/regex/issues
- npm.io page: https://npm.io/package/@forensic-js/regex

## Dependencies (1)

- [@forensic-js/utils](https://npm.io/package/@forensic-js/utils.md) 2.0.0

## Recent versions

- 1.0.2 (latest) — 2019-05-27
- 1.0.1 — 2019-05-07
- 1.0.0 — 2019-04-07

## README

# Regex

[![Build Status](https://travis-ci.org/harrison-ifeanyichukwu/regex.svg?branch=master)](https://travis-ci.org/harrison-ifeanyichukwu/regex)
[![Coverage Status](https://coveralls.io/repos/github/harrison-ifeanyichukwu/regex/badge.svg?branch=master)](https://coveralls.io/github/harrison-ifeanyichukwu/regex?branch=master)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![npm version](https://badge.fury.io/js/%40forensic-js%2Fregex.svg)](https://badge.fury.io/js/%40forensic-js%2Fregex)
![npm](https://img.shields.io/npm/dt/%40forensic-js%2Fregex.svg)

Regex is a module that builds on the existing `RegExp` module, making it easier working with text matching and replacment in JavaScript both in the `browser` and in `Node.JS` environment.

**Single Browser distributable bundle is located inside **dist** folder.**

## Installation

```bash
npm install @forensic-js/regex
```

## Usage Sample

```typescript
import {replace} from '@forensic-js/regex';

let text = 'Is is Is is Is';

console.log(replace('is', 'are', text)); // are are are are are

// respect case (case sensitive)
console.log(replace('is', 'are', text, true)); // Is are Is are Is

// replace only first occurence, case sensitive false
console.log(replace('is', 'are', text, false, 1)); // are is Is is Is

// replace only first 2 occurences, case sensitive false
console.log(replace('is', 'are', text, false, 2)); // are are Is is Is
```

## Replacing with a Callback method

```typescript
import {replaceCallback} from '@forensic-js/regex';

const text = 'He loves her';
console.log(replaceCallback(['he', 'she'], function(matches, count) {
    if (matches[0].toLowerCase() === 'he')
        return 'She';
    else {
        return 'him'
    };
}, text)); // logs She loves him
```

## Referencing captured groups in replacement text

to reference a captured parameter in replacement text, use the format `$:number`. e.g **$:1**, **$:2**, **$:3**

```typescript
import {replace} from '@forensic-js/regex';

const text = '2222 is the amount';
console.log(
    replace(/(\d+)/, '$$:1', text)).toEqual('$2222 is the amount')
);
```

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