santa
santa

Reputation: 12512

jQuery regex help needed

I need to take a string of text

var myText = $(this).text();

which looks something like this

<my text (10)>

and strip down all but numeric value. I tried this but failed:

var myNum = myText.match(/<.*\(|\)>/);

Help...

Upvotes: 0

Views: 65

Answers (2)

amit_g
amit_g

Reputation: 31250

var myNum = myText.replace(/[^0-9]/g, "");

EDIT:

var myNum = myText.match(/\(([0-9]+)\)/)[1];

Upvotes: 1

Jordan
Jordan

Reputation: 1238

var myNum = myText.match(/\((\d+)\)/)[1];

Upvotes: 1

Related Questions