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