Here is my code value = str.match(/$(\d+)/);
For example 1: HK$999 Display Result = 999
For example 2: HK$1,999.20 Display result = 1 (I would not want this result)
How can show the example 2 = 1999
Thank you all ^_^
Here is my code value = str.match(/$(\d+)/);
For example 1: HK$999 Display Result = 999
For example 2: HK$1,999.20 Display result = 1 (I would not want this result)
How can show the example 2 = 1999
Thank you all ^_^
This code should work fine first remove all the unnecessary comas from the string then select all the numbers before "."
var ragex = /(\d+)/g;
let str = "HR999";
str = "HK$1,999.20"
str = str.replace(/(,)/, '')
let res = str.match(ragex)[0];
the result will be at first index in the array
if you want numbers including.
use this ragex
var ragex = /\d+.\d+/g;