<h2>How do you find the phone numbers in 50,000 HTML pages?<br><br></h2>

<blockquote>
  <h3>Jeff Attwood posted 5 Questions for programmers applying for jobs:</h3>
  
  <p>In an effort to make life simpler for phone screeners, I've put together
  this list of Five Essential Questions
  that you need to ask during an SDE
  screen. They won't guarantee that your
  candidate will be great, but they will
  help eliminate a huge number of
  candidates who are slipping through
  our process today.</p>
  
  <p><strong>1) Coding</strong> The candidate has to write
  some simple code, with correct syntax,
  in C, C++, or Java.</p>
  
  <p><strong>2) OO design</strong> The candidate has to
  define basic OO concepts, and come up
  with classes to model a simple
  problem.</p>
  
  <p><strong>3) Scripting and regexes</strong> The
  candidate has to describe how to find
  the phone numbers in 50,000 HTML
  pages.</p>
  
  <p><strong>4) Data structures</strong> The candidate has
  to demonstrate basic knowledge of the
  most common data structures.</p>
  
  <p><strong>5) Bits and bytes</strong> The candidate has
  to answer simple questions about bits,
  bytes, and binary numbers.</p>
  
  <p>Please understand: what I'm looking
  for here is a total vacuum in one of
  these areas. It's OK if they struggle
  a little and then figure it out. It's
  OK if they need some minor hints or
  prompting. I don't mind if they're
  rusty or slow. What you're looking for
  is candidates who are utterly
  clueless, or horribly confused, about
  the area in question.</p>
  
  <p><strong><a href="http://www.codinghorror.com/blog/archives/001042.html" rel="noreferrer">>>> The Entirety of Jeff´s Original Post &lt;&lt;&lt;</a></strong></p>
</blockquote>

<p><br>
<strong>Note:</strong> Steve Yegge originally posed the Question.</p>

[{'answer_id': 48767, 'author': 'Ande Turner', 'author_id': 4857, 'author_profile': 'https://Stackoverflow.com/users/4857', 'pm_score': 1, 'selected': False, 'text': "<h2>Perl Solution</h2>\n<p>By: &quot;MH&quot; via codinghorror,com on September 5, 2008 07:29 AM</p>\n<pre><code>#!/usr/bin/perl\nwhile (&lt;*.html&gt;) {\n    my $filename = $_;\n    my @data     = &lt;$filename&gt;;\n\n    # Loop once through with simple search\n    while (@data) {\n        if (/\\(?(\\d\\d\\d)\\)?[ -]?(\\d\\d\\d)-?(\\d\\d\\d\\d)/) {\n            push( @files, $filename );\n            next;\n        }\n    }\n\n    # None found, strip html\n    $text = &quot;&quot;;\n    $text .= $_ while (@data);\n    $text =~ s#&lt;[^&gt;]+&gt;##gxs;\n\n    # Strip line breaks\n    $text =~ s#\\n|\\r##gxs;\n\n    # Check for occurrence.\n    if ( $text =~ /\\(?(\\d\\d\\d)\\)?[ -]?(\\d\\d\\d)-?(\\d\\d\\d\\d)/ ) {\n        push( @files, $filename );\n        next;\n    }\n}\n\n# Print out result\nprint join( '\\n', @files );\n</code></pre>\n"}, {'answer_id': 48788, 'author': 'Marcio Aguiar', 'author_id': 4213, 'author_profile': 'https://Stackoverflow.com/users/4213', 'pm_score': 2, 'selected': False, 'text': '<p>Made this in Java. The regex was borrowed from <a href="http://forums.msdn.microsoft.com/en-US/regexp/thread/8d4846c0-4eca-427a-b34a-856c7f8695cb/" rel="nofollow noreferrer">this forum</a>.</p>\n<pre><code>    final String regex = &quot;[\\\\s](\\\\({0,1}\\\\d{3}\\\\){0,1}&quot; +\n            &quot;[- \\\\.]\\\\d{3}[- \\\\.]\\\\d{4})|&quot; +\n            &quot;(\\\\+\\\\d{2}-\\\\d{2,4}-\\\\d{3,4}-\\\\d{3,4})&quot;;\n    final Pattern phonePattern = Pattern.compile(regex);\n    \n    /* The result set */\n    Set&lt;File&gt; files = new HashSet&lt;File&gt;();\n    \n    File dir = new File(&quot;/initDirPath&quot;);\n    if (!dir.isDirectory()) return;\n    \n    for (File file : dir.listFiles()) {\n        if (file.isDirectory()) continue;\n        \n        BufferedReader reader = new BufferedReader(new FileReader(file));\n        \n        String line;\n        boolean found = false;\n        while ((line = reader.readLine()) != null \n                &amp;&amp; !found) {\n            \n            if (found = phonePattern.matcher(line).find()) {\n                files.add(file);\n            }\n        }\n    }\n\n    for (File file : files) {\n        System.out.println(file.getAbsolutePath());\n    }\n</code></pre>\n<p>Performed some tests and it went ok! :)\nRemeber I\'m not trying to use the best design here. Just implemented the algorithm for that.</p>\n'}, {'answer_id': 48812, 'author': 'Pat', 'author_id': 238, 'author_profile': 'https://Stackoverflow.com/users/238', 'pm_score': 2, 'selected': False, 'text': "<pre><code>egrep '\\(?\\d{3}\\)?[-\\s.]?\\d{3}[-.]\\d{4}' *.html\n</code></pre>\n"}, {'answer_id': 48826, 'author': 'Jeremy', 'author_id': 1114, 'author_profile': 'https://Stackoverflow.com/users/1114', 'pm_score': 6, 'selected': True, 'text': '<pre><code>egrep "(([0-9]{1,2}.)?[0-9]{3}.[0-9]{3}.[0-9]{4})" . -R --include=\'*.html\'\n</code></pre>\n'}, {'answer_id': 48834, 'author': 'sieben', 'author_id': 1147, 'author_profile': 'https://Stackoverflow.com/users/1147', 'pm_score': 1, 'selected': False, 'text': '<p>i love doing these little problems, can\'t help myself.</p>\n\n<p>not sure if it was worth doing though since it\'s very similar to the java answer.</p>\n\n<pre><code>private readonly Regex phoneNumExp = new Regex(@"(\\({0,1}\\d{3}\\){0,1}[- \\.]\\d{3}[- \\.]\\d{4})|(\\+\\d{2}-\\d{2,4}-\\d{3,4}-\\d{3,4})");\n\npublic HashSet&lt;string&gt; Search(string dir)\n{\n    var numbers = new HashSet&lt;string&gt;();\n\n    string[] files = Directory.GetFiles(dir, "*.html", SearchOption.AllDirectories);\n\n    foreach (string file in files)\n    {\n        using (var sr = new StreamReader(file))\n        {\n            string line;\n\n            while ((line = sr.ReadLine()) != null)\n            {\n                var match = phoneNumExp.Match(line);\n\n                if (match.Success)\n                {\n                    numbers.Add(match.Value);\n                }\n            }\n        }\n    }\n\n    return numbers;\n}\n</code></pre>\n'}, {'answer_id': 110756, 'author': 'devinmoore', 'author_id': 15950, 'author_profile': 'https://Stackoverflow.com/users/15950', 'pm_score': -1, 'selected': False, 'text': '<p>Here\'s why phone interview coding questions don\'t work:  </p>\n\n<p>phone screener: how do you find the phone numbers in 50,000 HTML pages?</p>\n\n<p>candidate: hang on one second (covers phone) hey (roommate/friend/etc who\'s super good at programming), how do you find the phone numbers in 50,000 HTML pages?</p>\n\n<p>Save the coding questions for early in the in-person interview, and make the interview questions more personal, i.e. "I\'d like details about the last time you solved a problem using code".  That\'s a question that will beg follow-ups to their details and it\'s a lot harder to get someone else to answer it for you without sounding weird over the phone.</p>\n'}, {'answer_id': 716989, 'author': 'em70', 'author_id': 87079, 'author_profile': 'https://Stackoverflow.com/users/87079', 'pm_score': 2, 'selected': False, 'text': '<p>Borrowing 2 things from the C# answer from sieben, here\'s a little F# snippet that will do the job. All it\'s missing is a way to call processDirectory, which is left out intentionally :)</p>\n\n<pre><code>\nopen System\nopen System.IO\nopen System.Text.RegularExpressions\n\nlet rgx = Regex(@"(\\({0,1}\\d{3}\\){0,1}[- \\.]\\d{3}[- \\.]\\d{4})|(\\+\\d{2}-\\d{2,4}-\\d{3,4}-\\d{3,4})", RegexOptions.Compiled)\n\nlet processFile contents = contents |> rgx.Matches |> Seq.cast |> Seq.map(fun m -> m.Value)\n\nlet processDirectory path = Directory.GetFiles(path, "*.html", SearchOption.AllDirectories) |> Seq.map(File.ReadAllText >> processFile) |> Seq.concat\n</code></pre>\n'}, {'answer_id': 15592111, 'author': 'ruralcoder', 'author_id': 324308, 'author_profile': 'https://Stackoverflow.com/users/324308', 'pm_score': 2, 'selected': False, 'text': '<p>Here is a improved regex pattern</p>\n\n<pre><code>\\(?\\d{3}\\)?[-\\s\\.]?\\d{3}[-\\s\\.]?\\d{4}\n</code></pre>\n\n<p>It is able to identify several number formats</p>\n\n<ol>\n<li>xxx.xxx.xxxx</li>\n<li>xxx.xxxxxxx</li>\n<li>xxx-xxx-xxx</li>\n<li>xxxxxxxxxx</li>\n<li>(xxx) xxx xxxx </li>\n<li>(xxx) xxx-xxxx</li>\n<li>(xxx)xxx-xxxx</li>\n</ol>\n'}]
['https://Stackoverflow.com/questions/48744', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4857/']