I have the following code, but getting no output. When I run it here it seems to work:
https://regex101.com/r/FVkJfF/1
JavaScript
x
6
1
var strng = '[,][123,1][,][456,2][,][789,3][,][,][,][,][,][,][,][,]';
2
var rgx = [(.[0-9,]+)];
3
var outstr = strng.match(rgx).join(',');
4
Write(outstr);
5
6
To clarify, I aim to capture all the values between the brackets if they contain a number (including the opening and closing bracket of that group)
Guess I am doing something wrong somewhere?
Advertisement
Answer
Try this one instead:
JavaScript
1
2
1
/[d+,d+]/g
2
It matches a substring if it contains:
- an opening bracket
- an integer
- a comma
- another integer
- a closing bracket
… in that order, without any whitespace.
Also note that a regexp literal starts with /
. The way you’ve defined var rgx
in your snippet is a SyntaxError