-2

Regex link is https://regex101.com/r/xAQoU0/4. There it finds two matches.

const regex = /\$\$\[([(a-z-A-Z.)]*)]/;
const str = "<p>I have $$[worksAmount] works and $$[reviewsAmount] reviews</p>";
const match = regex.exec(str);
console.log(match)

But, when I run this snippet it logs in console only first match. So how to get all matches?

  • You have to set the _global_ flag `const regex = /\$\$\[([(a-z-A-Z.)]*)]/g;` This is what you're really doing https://regex101.com/r/CM5DYW/1. Also, exec returns an array in a different format than what you think. –  Jul 06 '20 at 22:05

1 Answers1

-1
const regex = /\$\$\[([(a-z-A-Z.)]*)]/g;
const str = "<p>I have $$[worksAmount] works and $$[reviewsAmount] reviews</p>";
const match = str.match(regex);
console.log(match)
Leon Aves
  • 739
  • 1
  • 7
  • 24