https://github.com/ajhsu/regextract
Extracting text with Regular Expression
https://github.com/ajhsu/regextract
javascript regexp regular-expression
Last synced: 10 months 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 (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-03-17T15:17:50.000Z (about 7 years ago)
- Last Synced: 2025-06-23T00:11:34.658Z (12 months ago)
- Topics: javascript, regexp, regular-expression
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# regextract
Extracting text with Regular Expression
[](https://www.npmjs.com/package/regextract)
[](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