I have a string that looks similar to this:
I want to strip the text until I get the value 500 & 705. I want them as two separate values. How can I do this in javascript?Code:tumblr_mgn6mfe9aD1rbaz5bo1_500.jpg (500×705)
Printable View
I have a string that looks similar to this:
I want to strip the text until I get the value 500 & 705. I want them as two separate values. How can I do this in javascript?Code:tumblr_mgn6mfe9aD1rbaz5bo1_500.jpg (500×705)
Something like this should work:
You will probably want to refer to a variable or fieldname.value instead of a literal though. If you just want to store or display that without using it in a calculation, you won't need the Number() function. BTW, result is not a reserved word, just the name of an array that will be created if it doesn't exist already.Code:result = "tumblr_mgn6mfe9aD1rbaz5bo1_500.jpg (500×705)".match(/.*\((\d*)×(\d*)\)/
if (result != null) {
var picHeight=Number(result[1]);
var picWidth=Number(result[2]); }
I tried your code but it doesn't seem to work. You can see online version here http://jsfiddle.net/97hHA/