In my Angular TypeScript code I have a function for formatting my value in this model:
1234
-> 1 234,000
First part of my function use regex like this:
// delete 0 in string start and make 3 digits packets
cleanedValue = cleanedValue.replace(/^0+(?=d)/, '').replace(/B(?=(d{3})+(?!d))/g, ' ');
It’s ok but Sonar give me a:
Make sure the regex used here, which is vulnerable to super-linear runtime due to backtracking, cannot lead to denial of service.
How can I do this without regex or without Sonar tell me this warning. Is this warning really positive?