-1

I need to grab data from this text from this page: http://www.chess.com/home/game_archive?sortby=&show=echess&member=deckers1066

I cannot seem to get it working using.

var text = document.body;

var results = text.match(/id=[0-9]*>/g);

I need to grab all occurrences that look something like this

/echess/game?id=60942234

I'm interested more in the id number

Yusuf Ali
  • 95
  • 2
  • 11
  • I think `document.body.toString(); // "[object HTMLBodyElement]"` would be the first insight into what's going wrong, http://stackoverflow.com/a/1732454/444991 should be the second. – Matt Dec 08 '12 at 12:21

2 Answers2

1

You've got two problems with your code; one is the string you want to search is document.body.innerHTML and the other is the RegExp is looking for the end tag to the element, > without a quote before it. Try this

var results = document.body.innerHTML.match(/id=\d+/g);

Note I completely ommited the end tag because this RegExp is greedy and it means you don't have to worry about HTML parsing.

Paul S.
  • 64,864
  • 9
  • 122
  • 138
0

Please don't use regular expressions for this. You should be using a proper DOM parser (there are many available for pretty much every language) and then selecting the IDs using that.

If you insist on using regex (which I would recommend against), Paul S's answer is the best.

callumacrae
  • 8,185
  • 8
  • 32
  • 49