0

I have the string

text ='something here width="560" something here'

and I would like to pull out the width value. I tried

width = text.match(/width=\"[^\"]/g);

but that just returns an array with one value = 5. Could someone give me a nudge in the right direction?

Thanks

2 Answers 2

3

Looks like you want:

var m = text.match(/width="([^"]+)/);
var width = m && m[1];

Note the + — a character class will only match one character by default.

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

Comments

1
/width=\"[^\"]+/g
              ^--- + means 1 or more

Without quantifier it matches exactly one character.

1 Comment

@minitech: it's not a ready to use code, but an extraction :-)

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.