javascript regular extracts of letters and numbers decimal

var item = {name:"PM2.5"};
item.nameFirst = item.name.replace(/[^a-zA-Z]/g, '');
item.nameLast = /(\d+(\.\d+)?)/.exec(item.name);
if (item.nameLast && item.nameLast.length > 0) {
    item.nameLast = item.nameLast[0];
}

console.log(item)

 

Guess you like

Origin www.cnblogs.com/yeminglong/p/11635385.html