This particular piece of code is expected to function correctly. The initial step involves removing any unnecessary commas from the string, followed by the extraction of all numbers appearing before a decimal point.
var ragex = /(\d+)/g;
let str = "HR999";
str = "HK$1,999.20"
str = str.replace(/(,)/, '')
let res = str.match(ragex)[0];
The resulting value will be found at the first index within the array returned.
If your requirement includes obtaining numbers alongside decimals, you should utilize the following regex pattern:
var ragex = /\d+.\d+/g;