match-any

0.0.1 • Public • Published

match-any v0.0.1

Search a string for substrings matching any number of provided RegExp objects.

const matchAny = require('match-any')
 
// Returns a sparse array
const matches = matchAny('a1 b2', /[a-z]/g, /[0-9]/g)
 
matches.forEach((match, index) => {
  console.log(`
    index = ${index}
    string = '${match[0]}'
    regex = /${match.regex.source}/g
  `)
})
 
/* Console output:
 *
 *   index = 0
 *   string = 'a'
 *   regex = /[a-z]/g
 *
 *   index = 1
 *   string = '1'
 *   regex = /[0-9]/g
 *
 *   index = 3
 *   string = 'b'
 *   regex = /[a-z]/g
 *
 *   index = 4
 *   string = '2'
 *   regex = /[0-9]/g
 */

Readme

Keywords

none

Package Sidebar

Install

npm i match-any

Weekly Downloads

0

Version

0.0.1

License

none

Last publish

Collaborators

  • aleclarson