0

I have a string that looks similar to this:

tumblr_mgn6mfe9aD1rbaz5bo1_500.jpg (JPEG Image, 500 × 705 pixels)

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?

2
  • 4
    Will the string always be in this exact format? Commented Jan 15, 2013 at 10:33
  • yes they will be in the exact format but different values Commented Jan 15, 2013 at 10:38

2 Answers 2

3
var match = /(\d+) × (\d+) pixels\)$/.exec('tumblr_mgn6mfe9aD1rbaz5bo1_500.jpg (JPEG Image, 500 × 705 pixels)')

Then match[1] and match[2] will contain the two values you are looking for (as strings).

Sign up to request clarification or add additional context in comments.

Comments

0

Here is how you can match the dimension:

var result = (/(\d+)\s*(×|x)\s*(\d+)\s*pixels\)$/g).exec('tumblr_mgn6mfe9aD1rbaz5bo1_500.jpg (JPEG Image, 500 × 705 pixels)');
console.log(result[1]); //"500"
console.log(result[3]); //"705"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.