I’ve below javascript program –
var rx = /^the values should(?: between (d+(.d+)?) and (d+(.d+)?))$/;
var sentence = "the values should between 1.1 and 2.7";
var arr = rx.exec(sentence);
console.log(JSON.stringify(arr));
I want to extract the number 1.1 and 2.7 into into an array from the matched line.
When I run the above program I get the below result
["the values should between 1.1 and 2.7","1.1",".1","2.7",".7"]
In the above program 1.1
becomes .1
and 2.7
becomes .7
.
How can I match it in javascript correctly.