I added a feature to my site map utility that does that. My routine is much more complex than what others have posted so far, and handles directory detection in some cases by comparing webpages retrieved through URLs with and without a trailing slash. A slashed target would break some links that end with a file, and some URL's point to an extensionless file that looks like a directory. My code is proprietary, but the instructions in the configuration utility currently read:

Slash Directory
Type yes to append a slash to each link target that points to a directory, when a trailing slash isn't already present (speeds loading of target page). Extensionless files will be detected and not slashed. Otherwise, type no or leave blank.

Slash Base
Type yes to append a slash to each link target that points to a base directory (domain name), when a trailing slash isn't already present. Otherwise, type no or leave blank. Targets that specify a home page's file, such as domain.com/index.html, will not be slashed. This feature adds consistency to link targets, but does not speed loading of target page.


In reply to Re: Regex - one and only one / at beginning and end of file path by Wassercrats
in thread Regex - one and only one / at beginning and end of file path by mikedshelton

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.