Creating Slugs from Titles?

Posted by James Jeffery on Stack Overflow See other posts from Stack Overflow or by James Jeffery
Published on 2010-06-07T20:59:44Z Indexed on 2010/06/07 21:12 UTC
Read the original article Hit count: 150

Filed under:
|
|

I have everything in place to create slugs from titles, but there is one issue. My RegEx replaces spaces with hyphens. But when a user types "Hi     there" (multiple spaces) the slug ends up as "Hi-----there". When really it should be "Hi-there".

Should I create the regular expression so that it only replaces a space when there is a character either side?

Or is there an easier way to do this?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about regex