0

I originally received help in this thread: Javascript to grab Javascript comments within <head>.

Where I wanted to use Greasemonkey/Javascript to grab a comment from within tags.

<html>
    <head>
    <!-- 12036,2011-11-29/11:02 -->
    <title>Products & Services</title>

The answer I received in the thread above grabbed the number "12036" and displayed this as an overlay on my page. Now I want to grab the second part (the date) ie "2011-11-29" and also display this as an overlay.

What do I need to add/change from the following to grab the date?

var commentNode = [].slice.call(document.head.childNodes).filter(function(node) {
        return node.nodeType == 8;
      })[0],
id = commentNode.data.match(/^\s*(\d+)/)[1];

var elem = document`.createElement('div');
elem.id = 'id-display';

elem.appendChild(document.createTextNode(id));

document.body.appendChild(elem);
Community
  • 1
  • 1
rlsaj
  • 735
  • 1
  • 12
  • 37
  • You just need to change the regular expression, to match everything between the comma and the space. Isn't that obvious? – Barmar May 06 '13 at 22:18
  • Sure, and what would that regular expression be? – rlsaj May 06 '13 at 22:26
  • I don't understand what's happening. I'm not a programmer and never claimed to be. I need basic programming help with this regular expression. – rlsaj May 06 '13 at 22:40
  • If you're not a programmer, why are you programming? – Barmar May 06 '13 at 22:50
  • @Barmar: long story. Thanks for the help. – rlsaj May 06 '13 at 22:53
  • I just hope you're not going to be posting here every day, asking us to write your application for you. This site is not supposed to be a substitute for doing your own work, it's for help when you run into roadblocks. – Barmar May 06 '13 at 22:54
  • Noted. Thanks for helping me with this roadblock. – rlsaj May 06 '13 at 23:09

1 Answers1

1

Replace the id = ... line with:

id = commentNode.data.match(/,(.*?)\s/)[1];

Go to regular-expressions.info to learn about regular expressions.

Barmar
  • 741,623
  • 53
  • 500
  • 612