<p>I am just starting to learn javascript, so I don't have the skills to figure out what I assume is a trivial problem.</p>

<p>I'm working with a Wordpress blog that serves as a FAQ for our community and I am trying to pull together some tools to make managing the comments easier.  <a href="https://stackoverflow.com/users/4465/levik">Internet Duct Tape's Greasemonkey tools, like Comment Ninja</a>, are helpful for most of it, but I want to be able to get a list of all the IP addresses that we're getting comments from in order to track trends and so forth.</p>

<p>I just want to be able to select a bunch of text on the comments page and click a bookmarklet (<a href="https://stackoverflow.com/users/8119/jacob">http://bookmarklets.com</a>) in Firefox that pops up a window listing all the IP addresses found in the selection.</p>

<p><strong>Update:</strong></p>

<p>I kind of combined a the answers from <a href="https://stackoverflow.com/users/4465/levik">levik</a> and <a href="https://stackoverflow.com/users/8119/jacob">Jacob</a> to come up with this:</p>

<pre><code>javascript:ipAddresses=document.getSelection().match(/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g).join("&lt;br&gt;");newWindow=window.open('', 'IP Addresses in Selection', 'innerWidth=200,innerHeight=300,scrollbars');newWindow.document.write(ipAddresses)
</code></pre>

<p>The difference is that instead of an <em>alert</em> message, as in levik's answer, I open a new window similar to Jacob's answer.  The <em>alert</em> doesn't provide scroll bars which can be a problem for pages with many IP addresses.  However, I needed the list to be vertical, unlike Jacob's solution, so I used the hint from levik's to make a <em><br></em> for the join instead of levik's <em>\n</em>.  </p>

<p>Thanks for all the help, guys.</p>

[{'answer_id': 72981, 'author': 'Dr. Bob', 'author_id': 12182, 'author_profile': 'https://Stackoverflow.com/users/12182', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://javascript.about.com/library/blip.htm" rel="nofollow noreferrer">Here</a> is a good article on obtaining the IP address of your visitors.  You could display this in addition to their comment if you wanted or include it as a label or field in your page so you can reference it later.</p>\n'}, {'answer_id': 73031, 'author': 'jtimberman', 'author_id': 7672, 'author_profile': 'https://Stackoverflow.com/users/7672', 'pm_score': 1, 'selected': False, 'text': '<p>Use a regular expression to detect the IP address. A couple examples:</p>\n\n<pre><code>/\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b/\n/^([1-9][0-9]{0,2})+\\.([1-9][0-9]{0,2})+\\.([1-9][0-9]{0,2})+\\.([1-9][0-9]{0,2})+$/\n</code></pre>\n'}, {'answer_id': 73723, 'author': 'levik', 'author_id': 4465, 'author_profile': 'https://Stackoverflow.com/users/4465', 'pm_score': 3, 'selected': True, 'text': '<p>In Firefox, you could do something like this:</p>\n\n<pre><code>javascript:alert(\n  document.getSelection().match(/\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b/g)\n  .join("\\n"))\n</code></pre>\n\n<p>How this works:</p>\n\n<ul>\n<li>Gets the selection text from the browser ("document.getSelection()" in FF, in IE it would be "document.selection.createRange().text")</li>\n<li>Applies a regular expression to march the IP addresses (as suggested by Muerr) - this results in an array of strings.</li>\n<li>Joins this array into one string separated by return characters</li>\n<li>Alerts that string</li>\n</ul>\n\n<p>The way you get the selection is a little different on IE, but the principle is the same. To get it to be cross-browser, you\'d need to check which method is available. You could also do more complicated output (like create a floating DIV and insert all the IPs into it).</p>\n'}, {'answer_id': 74377, 'author': 'Jacob', 'author_id': 8119, 'author_profile': 'https://Stackoverflow.com/users/8119', 'pm_score': 1, 'selected': False, 'text': "<h2>As a bookmarklet</h2>\n<pre><code>javascript:document.write(document.getSelection().match(/\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b/g))\n</code></pre>\n<p>Just create a new bookmark and paste that javascript in</p>\n<h2>How to do it in Ubiquity</h2>\n<pre><code>CmdUtils.CreateCommand({\n    name: &quot;findip&quot;,\n    preview: function( pblock ) {\n        var msg = 'IP Addresses Found&lt;br/&gt;&lt;br/&gt; ';\n        ips = CmdUtils.getHtmlSelection().match(/\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b/g);\n        if(ips){\n            msg += ips.join(&quot;&lt;br/&gt;\\n&quot;);\n        }else{\n            msg += 'None';\n        }\n        pblock.innerHTML = msg;\n    },\n\n    execute: function() {\n        ips = CmdUtils.getHtmlSelection().match(/\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b/g);\n        if(ips){\n            CmdUtils.setSelection(ips.join(&quot;&lt;br/&gt;\\n&quot;));\n        }\n    }\n})\n</code></pre>\n"}, {'answer_id': 74387, 'author': 'jtimberman', 'author_id': 7672, 'author_profile': 'https://Stackoverflow.com/users/7672', 'pm_score': 0, 'selected': False, 'text': '<p>Have a look at the <a href="https://www.squarefree.com/bookmarklets/pagedata.html#rot13_selection" rel="nofollow noreferrer" title="rot13 bookmarklet">rot13 bookmarklet</a> for an example of selecting text and performing an action (in this case substitution) when the bookmarklet is clicked.</p>\n'}]
['https://Stackoverflow.com/questions/72921', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12419/']