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
Post a Comment