Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda