Skip to content

Retrieves all the matches of a regex in a string, via a generator.

License

Notifications You must be signed in to change notification settings

fabiospampinato/string-matches-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stringMatches (Generator)

Retrieves all the matches of a regex in a string, via a generator.

This works exactly like string-match, but uses a generator.

Install

npm install string-matches-generator

Usage

import stringMatches from 'string-matches–generator';

// Let's get all the matches of a regex in a string, via a generator

const str = 'A tidy tiger tied a tighter tie to tidy her tiny tail';
const regex = /tidy/g; // Don't forget the `g` flag, or it won't work
const matches = [...stringMatches ( str, regex )];

console.log ( matches.length ); // => 2

License

MIT © Fabio Spampinato

About

Retrieves all the matches of a regex in a string, via a generator.

Resources

License

Stars

Watchers

Forks

Packages

No packages published