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

226
Views
.replace not replacing all chars [NODEJS]

I've searched all around the web for a response to this question,

Why do my .replace only replace chars that doesnt have any other char behind

My code is : const fixedstring = string.replace('&', '^&')

When i enter : &notepad.exe& has a string, it give me the output ^&notepad.exe& instead of ^&notepad.exe^&

Can someone help me ? (i've tried the /g)

Thanks for the guy that will help me or just read my post, thanks !

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

0

You can't use the global flag /g unless you are using regex to find the characters to replace. You are currently using a string to find, which will only match the first instance.

Instead, use the regex:

.replace(/&/g, "^&")

Here is a working example.

const stringToReplace = "&notepad.exe&"

const replaced = stringToReplace.replace(/&/g, '^&')

console.log(replaced)

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!