Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ajhsu/regextract
Extracting text with Regular Expression
https://github.com/ajhsu/regextract
javascript regexp regular-expression
Last synced: 15 days ago
JSON representation
Extracting text with Regular Expression
- Host: GitHub
- URL: https://github.com/ajhsu/regextract
- Owner: ajhsu
- Created: 2017-04-13T03:20:05.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-17T15:17:50.000Z (almost 6 years ago)
- Last Synced: 2024-12-08T01:21:53.045Z (about 1 month ago)
- Topics: javascript, regexp, regular-expression
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# regextract
Extracting text with Regular Expression
[![npm](https://img.shields.io/npm/v/regextract.svg)](https://www.npmjs.com/package/regextract)
[![Build Status](https://travis-ci.org/ajhsu/regextract.svg?branch=master)](https://travis-ci.org/ajhsu/regextract)## Install
```
npm install regextract --save
```## API
```js
var result = extract(text, RegExp);
```#### `result.matches`
Type: Array
Matches of RegExp patterns to the source text.
#### `result.extracts`
Type: Array
Captured groups of capturing parentheses within RegExp patterns to the source text.
#### `result.captured`
Type: Array
Alias to `result.extracts`.
## Usage
Require package
```js
var extract = require('regextract');
```Find matches
```js
extract('iPhone6, iPhone7, iPhone8, iPhoneX', /iPhone\d/g);// You'll get:
{
matches: ['iPhone6', 'iPhone7', 'iPhone8'],
extracts: []
}
```Get extracted texts
```js
extract('Price: NTD$299', /NTD\$(\d+)/g)// You'll get:
{
matches: ['NTD$299'],
extracts: ['299']
}
```## License
MIT