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

152
Views
Regular expression to replace middle chars of a string

I would like to replace middle 4 characters of a string with ****

For example: ABCDEFG should become AB****G

Please suggest a Regex to achieve this.

Note: The length of the string is always same.

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

0

Found the solution that I was looking for:

var s="ABCDEFG"
var reg=/\b(\w{2})\w+(\w)\b/g

s.replace(reg, '$1**$2');

output: AB****G

This will replace all the middle chars except first 2 and last 1 char in a string.

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!