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

156
Views
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 answers
Answer question

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 Report

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 Report
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!