logo image

Title to url friendly String generation


You cann't put the title as is in urls as it may contain spaces/ special characters etc, The better option is generating a url friendly String out of Title. For example instead Title to url friendly String generation its better have some thing like title-to-url-friendly-string-generation in urls. So basically i am replacing all special characters including spaces with - (Hyphen) and maintaining a constant case (Lower case). For this i have written a function for which you can pass your original Title and it returns the url friendly string.

function getLinkFromtitle(title) {
  if (title) {
    title = title.toLowerCase();
    title = title.replace(/\W+/g, "-");
    return title;
  return title;


console.log(getLinkFromtitle('Title to url friendly String generation'));
// this outputs : title-to-url-friendly-string-generation