http://www.perlmonks.org?node_id=966224


in reply to A module for creating "sane" URLs from "arbitrary" titles?

s/_-_/-/g; s/^_+//g; s/_+$//g;
Suggestion: replace the above with:
s/_(?:-_)+/_/g; s/^[-_]+//; s/[-_]+$//;

Replies are listed 'Best First'.
Re^2: A module for creating "sane" URLs from "arbitrary" titles?
by Corion (Patriarch) on Apr 20, 2012 at 17:58 UTC

    Thanks for the additions.

    I'd like abc - def to become abc-def, which is why I'll be using the dash as a replacement instead of the underscore in s/_(?:-_)+/-/g; , but eliminating trailing dashes and repeated dashes is a good addition indeed. Even though it makes links to C++ and C equivalent :).

    Update: I noticed that C++ and C were already converted to the same URL fragment, C anyway.

      I meant to write s/_(?:-_)+/-/g, instead of replacing a line of _-_-_-_ with an underscore.