0

I tried this code:

/\[\[(.*?)\]\]/g

to return multiple matches from text like this: some [[text]] and even [[more]] text. But instead oftext, more, it only returns text. What I am doing wrong? Thanks in advance.

FPeter
  • 43
  • 2
  • 9

3 Answers3

1

Your regex is correct which includes the global match flag /g.

If you use the match method it should work fine.

var stringToTest = "some [[text\]\] and even [[more]] text";
var regexToTest = /\[\[(.*?)\]\]/g;

var matches = stringToTest.match(regexToTest);
console.log(matches)
Abhinav Galodha
  • 9,293
  • 2
  • 31
  • 41
0

The regex is ok:

var test = "[[text]] and even [[more]] text.".match(/\[\[(.*?)\]\]/g);
console.log(a);
> ["[[text]]", "[[more]]"]
streetturtle
  • 5,472
  • 2
  • 25
  • 43
0

Try to match the whole regular expression multiple times. Like this: /([[.*?]])+/g

PVRT
  • 480
  • 4
  • 13