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

132
Views
Replace text using regular expressions js vanilla

I am trying to replace the text of an input. If I enter this value (11111111), the output format should be (1,111,111-1). I have no idea how to do this using js vanilla. I am trying to use regex and replace but I'm very confused.

let regExp = /^[1-9].\d{3}.\d{3}-\d{1}$/g;  
let newInput = input.replace(regExp, '$1,');
console.log( newInput);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The regex is for the match, which must match the input string. Use the replacement pattern to reformat the output:

let input = '11111111'
let regExp = /^(\d)(\d{3})(\d{3})(\d)$/g;  
let newInput = input.replace(regExp, '$1,$2,$3-$4');
console.log( newInput);

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!