Get all the matches for a regular expression in a string.
# Using npm
npm install --save match-all
# Using yarn
yarn add match-all
const matchAll = require("match-all");
let s = "Hello _World_ and _Mars_";
console.log(matchAll(s, /_([a-z]+)_/gi).toArray());
// => [ "World", "Mars" ]
// Get matches one by one
let m = matchAll(s, /_([a-z]+)_/gi);
console.log(m.next());
// => "World"
console.log(m.next());
// => "Mars"
console.log(m.next());
// => null
let multipleGroup = "Hello _World001_ and _World002_";
console.log(matchAll(multipleGroup, /_([a-z]+([0-9]+))_/gi).toArray());
// => [ "World", "Mars" ]
// Get matches one by one
let multipleMatch = matchAll(multipleGroup, /_([a-z]+([0-9]+))_/gi);
console.log(multipleMatch.nextRaw());
// => [..., "World001", "001"]
console.log(multipleMatch.nextRaw());
// => [..., "World002", "002"]
let m2 = matchAll("Hello _World_, _Mars_, _Pluto_ and _Moon_!", /_([a-z]+)_/gi);
console.log(m2.next());
// => "World"
// Reset the match index
m2.reset();
console.log(m2.next());
// => "World"
console.log(m2.next());
// => "Mars"
// Set the match index to 20
m2.reset(20);
console.log(m2.next());
// => "Pluto"
There are few ways to get help:
- Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
- For bug reports and feature requests, open issues. 🐛
- For direct and quick help, you can use Codementor. 🚀
Get all the matches for a regular expression in a string.
-
String
s
: The input string. -
RegExp
r
: The regular expression.
- Object An object containing the following fields:
-
input
(String): The input string. -
regex
(RegExp): The regular expression. -
next
(Function): Get the next match. -
toArray
(Function): Get all the matches. -
reset
(Function): Reset the index.
Get the next match in single group match.
- String|null The matched snippet.
Get the next match in raw regex output. Usefull to get another group match.
- Array|null The matched snippet
Get all the matches.
- Array The matched snippets.
Reset the index.
-
Number
i
: The new index (default:0
).
- Number The new index.
Have an idea? Found a bug? See how to contribute.
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:
-
Starring and sharing the projects you like 🚀
-
—I love books! I will remember you after years if you buy me one. 😁 📖
-
—You can make one-time donations via PayPal. I'll probably buy a
coffeetea. 🍵 -
—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).
-
Bitcoin—You can send me bitcoins at this address (or scanning the code below):
1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6
Thanks! ❤️
If you are using this library in one of your projects, add it in this list. ✨
@0xged/hardhat-deploy
@4000d/hardhat-deploy
@anthonymartin/hardhat-deploy
@apify/markdown
@bahuy3103/hardhat-deploy
@baking-bad/vjsf
@cloedu/vuetify-jsonschema-form
@dev7ch/vuetify-jsonschema-form
@dhis2/cli-utils-docsite
@ed3ath/hardhat-deploy
@edgar-orozco/vuetify-jsonschema-form
@elvis-krop/hardhat-deploy
@emartech/collect-font-families
@eonian/hardhat-deploy
@float-capital/hardhat-deploy
@fvictorio/buidler-deploy
@holographxyz/hardhat-deploy-holographed
@humafara/evmhuma
@idkravitz/hardhat-deploy
@innoswap/core
@kangafinance/hardhat-deploy
@koumoul/vuetify-jsonschema-form
@layerzerolabs/hardhat-deploy
@layerzerolabs/hardhat-tron
@lerna-test-v1/markdown
@malatrax/hardhat-deploy
@mikeraymcdonald/hardhat-deploy
@miragon/vjsf
@muenchen/vjsf
@mvandenburgh/vjsf
@nickjfree/vuetify-jsonschema-form
@nirin100/quadratic-protocol
@nirin100/quadratic-sdk
@openhat/cli-utils-docsite
@pahor167/hardhat-deploy
@phydy/lend
@sanv/apify-shared
@sheetbase/app-scripts
@sheetbase/server-scripts
@strong-config/node
@tiemma/sonic-core
@vechain.energy/hardhat-deploy
@vitaliikorsakov/thelib
@x1b/vuetify-jsonschema-form
@zippie/hardhat-deploy
apify-shared
autocreatetomorokopi
autoload-modules-loader
blazepack
bot-peripheral
buidler-deploy
candy-moon-native
csv-to-lines
docker-compose-viz
emojer
evmhuma
google-font-downloader
harbor-hardhat-deploy
hardhat-deploy
hardhat-deploy-akv
hardhat-deploy-hardware-wallet
hardhat-deploy-immutable-proxy
hardhat-deployment
html_proc
json-schema-for-vuetify
lb4-utils
navdata-parser
opengate-vjsf
quadratic-sdk
qudratic-ui
quoridorn-server-lib
quoripagos-server-core
react-native-tailwind-style
react-navigation-generated-cli
redfishrepotest
rn-tailwindcss
rs-web-reactor
rucksack
shadows-hardhat-deploy
tailwind-rf
tailwind-rn-io
tailwindcss-rn
text-testing-mocha
trello-react-scripts
waqueplus