jquery - Javascript regex get the number part from a specific word -


say have element these classes: "floatleft item4".

if want save number "4" variable "item4" how that?

i think use pattern "/item(\d+)/" use replace or match , how?

you can use match this:

var str = "item4",     num = +str.match(/item(\d+)/)[1]; // => 4 

i used unary + cast number. can use parseint or number constructor instead.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -