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

173
Views
Replacing a specific spaces with dashes

Trying to replace specific spaces with dashes and lowercase the string

e.g.

"1.0 Domain - sub & domain"

"1.0-Domain-sub&domain"

Tried

str.replace(/\s+/g, '-').toLowerCase();
-> 1.0-domain---sub-&-domain
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could capture either - or & between optional whitespace chars and replace that with only the captured char, or else match 1 or more whitespace chars to be replaced with an empty string using the replacer function.

let str = "1.0 Domain - sub & domain";

str = str.replace(/\s*([&-])\s*|\s+/g, (m, g1) => g1 ? g1 : '-').toLowerCase();

console.log(str)

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!