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?

3dgoo
  • 15,546
  • 5
  • 45
  • 57
tsurti
  • 17
  • 4

1 Answers1

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.

Barmar
  • 669,327
  • 51
  • 454
  • 560