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

231
Views
I want to remove only one character before particular symbol for example:

I want to remove a specific character, as well as the one before it (in this case # and its preceding character). Example:

"ab#c" -> "ac"
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Use a regex and String.replace:

const inp = "ab#c";
const match = /.#/;
const out = inp.replace(match, "");

console.log(out);

Note that this removes any character preceding a '#' in your original string, but only a single occurrence. Add the g flag to match and replace all occurrences, and use [a-zA-Z] to just match letters.

If you want to work the other way (character following, not preceding), and want to replace #c but not \#c, just add that as well:

const inp = "ab\\#c3#cc";
const match = /[^\\]{1}#./;
const out = inp.replace(match, "");

console.log(out);

about 4 years ago · Juan Pablo Isaza Report

0

You can use global regex replace

const inputStr = "ab#c de#f gh#i";

const regxStr = /.#/g;
const outputStr = inputStr.replace(regxStr, "");

console.log(outputStr);

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!