javascript - Split number and string from the value using java script or regex -
i have value "4.66lb"
and want separate "4.66" , "lb" using regex.
i tried below code, separates number "4,66"!! want both values 4.66 , lb.
var text = "4.66lb"; var regex = /(\d+)/g; alert(text.match(/(\d+)/g));
have seek with:
var res = text.match(/(\d+(?:\.\d+)?)(\d+)/);
res[1]
contains 4.66
res[2]
contains lb
in order match 4/5lb
, use:
var res = text.match(/(\d+(?:[.\/]\d+)?)(\d+)/);
javascript regex string numbers
No comments:
Post a Comment