Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

ikatyang/regex-iterator

Repository files navigation

regex-iterator

npm build coverage

string matching iterator using regular expression

Changelog

Install

# using npm
npm install --save regex-iterator

# using yarn
yarn add regex-iterator

Usage

import * as regex_iterator from 'regex-iterator';

const spread_sample = () => {
  const iterator = regex_iterator.create(/([0-9])([a-z])/g, '1a 2b 3c');
  return [...iterator]; //=> [['1a', '1', 'a'], ['2b', '2', 'b'], ['3c', '3', 'c']]
};

const take_sample = () => {
  const iterator = regex_iterator.create(/([0-9])([a-z])/g, '1a 2b 3c');
  return regex_iterator.take(
    iterator,
    match => match[2] !== 'c',
    match => `${match[1]}-${match[2]}`,
  ); //=> ['1-a', '2-b']
};

Development

# lint
yarn run lint

# build
yarn run build

# test
yarn run test

License

MIT © Ika

About

[DEPRECATED] use String.prototype.matchAll instead

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •