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);
7
  • You just need to change the regular expression, to match everything between the comma and the space. Isn't that obvious? Commented May 6, 2013 at 22:18
  • Sure, and what would that regular expression be? Commented May 6, 2013 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. Commented May 6, 2013 at 22:40
  • If you're not a programmer, why are you programming? Commented May 6, 2013 at 22:50
  • @Barmar: long story. Thanks for the help. Commented May 6, 2013 at 22:53

1 Answer 1

1

Replace the id = ... line with:

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

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

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.