Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
Format a string to only lowercase letters and underscores to make it usable for URLs in Javascript

I need to create sanitized URLs slugs from title field written by users. The input will be something like:

const title = 'Puede àgregar unÁ imagen en miniatura (JPG, PNG, GIF) a tu_publicación-que *hola* #@\÷@¡'¿¸˛¸ aparecerá en todas las listas del foro. Debe ser una URL de imagen válida, nosotros nos encargamos de cambiarle el tamaño.'

And i need to generate a string that is sanitized like this:

'puede_agregar_una_imagen_en_miniatura_jpg_png_gif_a_tu_publicacion_que_hola_aparecera_en_todas_las_listas_del_foro_debe_ser_una_URL_de_imagen_valida_nosotros_nos_encargamos_de_cambiarle_el_tamano'

I tried to use replace() method but once I get into the regex part i cannot figure out how to match more than spaces.

title.replace(/[\s-,*()#$%]/g, '_').toLocaleLowerCase()

I want to be able to replace:

  • All symbols (*,) to nothing.
  • All - to _
  • All spaces to underlines '_'
  • All áóúíéèàòù, etc. to normalized lettters.
  • other characters like ñ should be replaced to n
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!