0

I am trying to find two values which are in the following format where I have two numbers of indeterminate length separated by a space.

<div name='something'>123 456</div><other HTML...> </other HTML>

Using the unique name='something' I want to know what the first number and second numbers are.

I am doing the following

var xhack = arraytrans.match("<div name='something'>(.*)</div>");
var values = xhack[1];
var z_value = values.split(' ')[0];
var x_value = values.split(' ')[1];

However this results in scenarios where the x value ends up being a bunch of trailing HTML from <other HTML>.

Any ideas what the right regex is to get x and z values here?

4

1 Answer 1

1

Your HTML has name=something, but your regexp is looking for name='something' (with quotes around something). You need to change it to:

var xhack = arraytrans.match("<div name=something>([^<]*)</div>");

I've also changed .* to [^<]* so that it won't match across multiple DIVs.

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

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.