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 replace digits with a character x times the match's length

Got the regex (?<!a|\d)[0-9]{6,} to match any digits with 6 in length or more, but that do not start with \ or digits.

Previously, I used I used [0-9] in replace("[0-9]", "x"), and it would replace 111 with xxx.

But now with the new formula replace("(?<!a|\d)[0-9]{6,}", "x") it just replaces with one x.

How can I make it so it continues the old behavior? I tried to use a function but it did not seem to work very well (using Zoho mail which uses weird JS language)

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

0

Use a function as the replacement. It can then repeat the character the same number of times as the length of the match.

console.log('123456'.replace(/(?<!a|\d)[0-9]{6,}/g, match => "x".repeat(match.length)));

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!