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.
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.
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)
The regex is ok:
var test = "[[text]] and even [[more]] text.".match(/\[\[(.*?)\]\]/g);
console.log(a);
> ["[[text]]", "[[more]]"]