String Regex matchAll not working

Hi,

When using a regex to find some substrings, I cannot get matchAll to work. It returns an empty Object. Match works find, but I need to use matchAll.
Hope someone know how to fix this.

Created a basic item function node example:

I think this is a tricky one. replaceAll might work in the browser while testing, but it doesn’t work in the node backend.
Seeing as you’re using a regex with /g, trying using .replace() instead

1 Like

Hi @pemontto

Thats the thing, In do not want to just replace them all :slight_smile:

OK, sorry I misread that thinking it was replaceAll.

In that case, matchAll returns an iterator, so you’ll need to “unpack” it:

item.matchedAll = [...text.matchAll(regex)];
2 Likes

Hi @pemontto

Ah, that could explain it indeed. Will try later today when I got the chance.
Thanks!

Hi @pemontto

I have tried it, it works sorta. I expected to get some more information on the match like the index. Your solution gave me the idea to try it like this, and it worked to get the index. So Thanks!
image

1 Like