Reputation: 6460
I'm trying to write a RegExp to allow this format : 5555.5555
, and any other number should be parsed out/replaced with an empty string (or something).
I've tried a few different things, namely:
/((^[\d]{5,})|([\d]{1,4}\.?))/g
- try to get everything that is not accepted and everything within 4 digits of an optional decimal so I can use the match in the .replace
method.
The ultimate goal is to take an input of 55555555.5555555
and spit back out 5555.5555
. I'm struggling with the fact that it matches a 5.
but doesn't give back the entire 5555.
.
Upvotes: 0
Views: 31
Reputation: 92527
Try
let str= "55555555.5555555";
let r= str.match(/\d{4}\.\d{4}/);
console.log(r[0]);
Upvotes: 1