Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

157
Vistas
Regex to convert URL to string

REGEX ONLY

I exclusively need Javascript regex code to convert URLs like

https://hello.romeo-juliet.fr
https://hello.romeojuliet.co.uk 
https://hello.romeo-jul-iet.fr 
https://hello.romeo-juliet.com

into this string romeojuliet

Basically want to get the alphabetic domain name with removing all other characters and https://, com/co.uk/fr etc Top Level Domains

Would be helpful if done using JS replace. I tried till here

let url="https://hello.romeo-juliet.fr";
const test=url.replace(/(^\w+:|^)\/\/(\w+.)/, '');
console.log(test);

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

A non regex solution:

Get the host of the URL (by parsing the string with the URL() constructor and getting its host property), split by a period and get the second item in the resulting array, then remove all occurences of -:

let url="https://hello.romeo-juliet.fr";
const test = new URL(url).host.split(".")[1].replaceAll("-", '');
console.log(test);

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use it with no regex as the following:

let url="https://hello.romeo-juliet.fr";
url.substring(url.indexOf(".")+1, url.lastIndexOf("."));
// result: romeo-juliet

I hope this answers your question

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda