“Slug JavaScript” Código de respuesta

Slug JavaScript

var slug = "CodePadding Rahman     ( Mizan ) 12456 <> title";
slug = slug.toLowerCase().replace(/[^\w-]+/g, '-');
console.log(slug); // codepadding-rahman-mizan-12456-title
CodePadding

Java Script Convertir texto en babosa

function convertToSlug(Text)
{
    return Text
        .toLowerCase()
        .replace(/ /g,'-')
        .replace(/[^\w-]+/g,'')
        ;
}
Muddy Mockingbird

Slug JavaScript

function makeSlug(slug){
	return slug.toLowerCase().replace(/[^\w-]+/g, '-');
}
let slug = makeSlug("CodePadding Rahman     ( Mizan ) 12456 <> title")
CodePadding

Slug JavaScript

var slug = "CodePadding Rahman     ( Mizan ) 12456 <> title";
//change all characters except numbers and letters
slug = slug.replace(/[^a-zA-Z0-9]/g, ' ');
//remove multiple space to single
slug = slug.replace(/  +/g, ' ');
// remove all white spaces single or multiple spaces
slug = slug.replace(/\s/g, '-').toLowerCase();
console.log(slug)
// output - codepadding-rahman-mizan-12456-title
CodePadding

Crear babosa en JavaScript

function makeSlug(slug){
  let finalSlug = slug.replace(/[^a-zA-Z0-9]/g, ' ');
  //remove multiple space to single
  finalSlug = slug.replace(/  +/g, ' ');
  // remove all white spaces single or multiple spaces
  finalSlug = slug.replace(/\s/g, '-').toLowerCase().replace(/[^\w-]+/g, '-');
  return finalSlug;
}

//example of work 
let slug = makeSlug('What Is a CSS Framework? (And When to Use 6 Popular Options)           ') 

console.log(slug) // what-is-a-css-framework---and-when-to-use-6-popular-options------------
Sharifur Robin

ES6 JS Slug de String

function slugify(string) {
  return string
    .toString()
    .trim()
    .toLowerCase()
    .replace(/\s+/g, "-")
    .replace(/[^\w\-]+/g, "")
    .replace(/\-\-+/g, "-")
    .replace(/^-+/, "")
    .replace(/-+$/, "");
}
Jeff Le

Respuestas similares a “Slug JavaScript”

Preguntas similares a “Slug JavaScript”

Más respuestas relacionadas con “Slug JavaScript” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código