1.0.3 • Published 7 years ago
regexallmatches v1.0.3
(⚫➕❓) regexAllMatches
regexAllMatches is a simple module that works to get all matches of a regular expression
◼ Installation
npm install regexallmatches --save
📋 Usage
regexAllMatches(string, regex)
;
Params
- string - String to which matches will be searched
- regex - Regex object or a string with a valid regex expression
const regexAllMatches = require("regexallmatches");
regexAllMatches("planir", /^[a-z0-9_-]{3,16}$/);
/** =>
* {
* regex: /^[a-z0-9_-]{3,16}$/,
* string: 'planir',
* groups: {'0': [ 'planir' ]}
* }
*/
// Multiple matches
regexAllMatches("uno dos tres", /[a-z]+/g)
/** =>
* {
* regex: /[a-z]+/g,
* string: 'uno dos tres',
* groups: { '0': [ 'uno', 'dos', 'tres' ] }
* }
*/
/**
* Digits allowed to username
* @var Number between_digits
*/
var between_digits = "3,16";
// You can pass a string on the second argument and a third argument in the function to indicate the flags
regexAllMatches("marcos8", '^[a-z0-9_-]{' + between_digits + '}$', 'g').groups);
// => { '0': [ 'marcos8' ] }