Reputation: 555
From string liike this "42.901189372459974,71.36591345071793"; i try to get numbers 42.901189 71.365913
var crds ="42.901189372459974,71.36591345071793";
var expr = new RegExp("[0-9][0-9]\.[0-9][0-9][0-9][0-9][0-9][0-9]","gim");
var matchedstr = crds.match(expr);
and in result i recevied 3 numbers 42.901189 ,372459,71.36591 but for me i need only 2
Upvotes: 0
Views: 606
Reputation: 45121
You need to escape \
when using RegExp
constructor
var expr = new RegExp("[0-9][0-9]\\.[0-9][0-9][0-9][0-9][0-9][0-9]","gim");
But there is no need to use it in this case.
var expr = /\d{2}\.\d{6}/gim; // the same as above
Upvotes: 1