https://github.com/samliebl/regex-map-replace
Run a text string through an array of individual match-replace regular expressions.
https://github.com/samliebl/regex-map-replace
map match regex regexp regular-expression replace replace-text string-formatter
Last synced: 12 months ago
JSON representation
Run a text string through an array of individual match-replace regular expressions.
- Host: GitHub
- URL: https://github.com/samliebl/regex-map-replace
- Owner: samliebl
- License: mit
- Created: 2019-10-04T07:50:07.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-24T13:49:21.000Z (almost 6 years ago)
- Last Synced: 2024-05-08T12:35:50.008Z (almost 2 years ago)
- Topics: map, match, regex, regexp, regular-expression, replace, replace-text, string-formatter
- Language: JavaScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# regex-map-replace #
Run a text string through an array of individual match-replace regular expressions.
## Overview ##
This is a simple npm module built to clean up text strings. It’s a single function that takes two parameters: `str` and `map`. `str` is a string of text. `map` is an array of objects, each with two properties: `match` and `replace`. These two properties are a dictionary, with `match` being the actual regular expression for your desired matching substring; `replace` being a string you want to replace it with.
## Installation ##
```sh
$ npm install regex-map-replace
```
## Example ##
```js
var regexMapReplace = require('regex-map-replace');
var map = [{
match: /Lorum/,
replace: 'Lorem'
},{
match: /doler/,
replace: 'dolor'
},{
match: /amit/,
replace: 'amet'
}];
var test = regexMapReplace('Lorum ipsum doler sit amit.', map);
console.log(test);
// Expected result: 'Lorem ipsum dolor sit amet.'
```