function retNumb(a){ var Numb = +a.replace(/[^\d]*(\d+)[^\d]*$/,'$1'); return Numb; } var AttStr = "strenght(15)" var AttStr2 = "knows_trade_12" // alert(retNumb(AttStr)); alert(retNumb(AttStr2));