Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: A module for creating "sane" URLs from "arbitrary" titles?

by JavaFan (Canon)
on Apr 20, 2012 at 17:50 UTC ( #966224=note: print w/replies, xml ) Need Help??

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 (Pope) 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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://966224]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2018-05-27 17:58 GMT
Find Nodes?
    Voting Booth?