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

284
Views
Regex to replace commas between a positive number and negative number
        global=global.toString().replace(/(\d+),,,(?=\d)/g, '$1,.');
  1. I am replacing the commas here. I need to replace the commas in between a positive and the second a negative number.

  2. I am replacing the commas here. I need to replace the commas in between a positive and the second a positive or negative number.

How do I do both of these?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

For example

const global = '1,-1,2,4,-2';
global.replace(/(-?\d+),(?=-?\d+)/g, '$1,.');

will output

'1,.-1,.2,.4,.-2'

So, you just need to add -? in your expression to indicate it is possible to be positive or negative.

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!