Indeed. If you make the mistake of using that RE you will have broken code. It will look right to you. It will work in your tests. But if someone like me comes along who knows how to put names and passwords in URLs, it will break and I won't be happy.

Put names and passwords in URLs? Most people don't know that you can do that. But try it:

http://name:password@www.company.com/whatever/to/get.html
Substitute in a name and password you use. Substitute in a protocol like ftp if that is easier. Give it a shot from your browser, LWP::Simple, etc.

This pattern is in the spec. It will work with any tool that I have ever tried. It will work with every protocol. If it does not work with your tool, then that is a bug.

This is why japhy would have used the standard library. He doesn't know the spec off of the top of his head. He knows he doesn't. And rather than finding it and having to figure out how to do the whole thing correctly, he can just use an existing library and be confident that it will Just Work. By contrast his off-the-cuff solution will work for 99% of the domain space, but (exactly as he predicted) will break somewhere...

The goal is be right with as little work as possible. So use the module.


In reply to Re (tilly) 2: Regexes and URIs by tilly
in thread Regexes and URIs by Amoe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.