<p>I was reading <a href="https://stackoverflow.com/questions/6173/regular-expression-for-parsing-links-from-a-webpage">this question</a> about how to parse URLs out of web pages and had a question about the <a href="https://stackoverflow.com/questions/6173/regular-expression-for-parsing-links-from-a-webpage#6183">accepted answer</a> which offered this solution:</p>

<pre class="lang-none prettyprint-override"><code>((mailto\:|(news|(ht|f)tp(s?))\://){1}\S+)
</code></pre>

<p>The solution was offered by <a href="https://stackoverflow.com/users/350/csmba">csmba</a> and he credited it to <a href="http://regexlib.com/Search.aspx?k=URL" rel="nofollow noreferrer">regexlib.com</a>. Whew. Credits done.</p>

<p>I think this is a fairly naive regular expression but it's a fine starting point for building something better.  But, my question is this:</p>

<p>What is the point of <code>{1}</code>? It means "exactly one of the previous grouping", right? Isn't that the default behavior of a grouping in a regular expression? Would the expression be changed in any way if the <code>{1}</code> were removed?</p>

<p>If I saw this from a coworker I would point out his or her error but as I write this the response is rated at a 6 and the expression on regexlib.com is rated a 4 of 5. So maybe I'm missing something?</p>

[{'answer_id': 13475, 'author': 'Marius', 'author_id': 1585, 'author_profile': 'https://Stackoverflow.com/users/1585', 'pm_score': 1, 'selected': False, 'text': "<p>I don't think it has any purpose. But because RegEx is almost impossible to understand/decompose, people rarely point out errors. That is probably why no one else pointed it out. </p>\n"}, {'answer_id': 13483, 'author': 'jj33', 'author_id': 430, 'author_profile': 'https://Stackoverflow.com/users/430', 'pm_score': 2, 'selected': False, 'text': '<p>@<a href="https://stackoverflow.com/questions/13470/question-about-specific-regular-expression#13479">Rob</a>: I disagree.  To enforce what you are asking for I think you would need to use negative-look-behind, which is possible but is certainly not related to use {1}.  Neither version of the regexp address that particular issue.</p>\n\n<p>To let the code speak:</p>\n\n<pre><code>tibook 0 /home/jj33/swap &gt; cat text\nText this is http://example.com text this is\nText this is http://http://example.com text this is\ntibook 0 /home/jj33/swap &gt; cat p\n#!/usr/bin/perl\n\nmy $re1 = \'((mailto\\:|(news|(ht|f)tp(s?))\\://){1}\\S+)\';\nmy $re2 = \'((mailto\\:|(news|(ht|f)tp(s?))\\://)\\S+)\';\n\nwhile (&lt;&gt;) {\n  print "Evaluating: $_";\n  print "re1 saw \\$1 = $1\\n" if (/$re1/);\n  print "re2 saw \\$1 = $1\\n" if (/$re2/);\n}\ntibook 0 /home/jj33/swap &gt; cat text | perl p\nEvaluating: Text this is http://example.com text this is\nre1 saw $1 = http://example.com\nre2 saw $1 = http://example.com\nEvaluating: Text this is http://http://example.com text this is\nre1 saw $1 = http://http://example.com\nre2 saw $1 = http://http://example.com\ntibook 0 /home/jj33/swap &gt;\n</code></pre>\n\n<p>So, if there is a difference between the two versions, it\'s doesn\'t seem to be the one you suggest.</p>\n'}, {'answer_id': 13484, 'author': 'Blair Conrad', 'author_id': 1199, 'author_profile': 'https://Stackoverflow.com/users/1199', 'pm_score': 2, 'selected': True, 'text': '<p>@Jeff Atwood, your interpretation is a little off - the {1} means match exactly once, but has no effect on the "capturing" - the capturing occurs because of the parens - the braces only specify the number of times the pattern must match the source - once, as you say.</p>\n\n<p>I agree with @Marius, even if his answer is a little terse and may come off as being flippant. Regular expressions are tough, if one\'s not used to using them, and the {1} in the question isn\'t quite error - in systems that support it, it does mean "exactly one match". In this sense, it doesn\'t really do anything.</p>\n\n<p>Unfortunately, contrary to a now-deleted post, it doesn\'t keep the regexp from matching <code>http://http://example.org</code>, since the \\S+ at the end will match one or more non-whitespace characters, including the <code>http://example.org</code> in <code>http://http://example.org</code> (verified using Python 2.5, just in case my regexp reading was off). So, the regexp given isn\'t really the best. I\'m not a URL expert, but probably something limiting the appearance of ":"s and "//"s after the first one would be necessary (but hardly sufficient) to ensure good URLs.</p>\n'}, {'answer_id': 13486, 'author': 'Jeff Atwood', 'author_id': 1, 'author_profile': 'https://Stackoverflow.com/users/1', 'pm_score': 2, 'selected': False, 'text': '<p>I don\'t think the {1} has any valid function in that regex. </p>\n\n<blockquote>\n  <p><strong>(**mailto:|(news|(ht|f)tp(s?))://</strong>){1}**</p>\n</blockquote>\n\n<p>You should read this as: "capture the stuff in the parens exactly one time". But we don\'t really care about capturing this for use later, eg $1 in the replacement. So it\'s pointless.</p>\n'}]
['https://Stackoverflow.com/questions/13470', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/430/']