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

180
Views
find all letters without repeating regex

help me please to find all letters in string without repeating using regex JS.

Examples:

let str = "abczacg";
str = str.match(/ pattern /); // return has to be: abczg

str = "aabbccdd" //return:abcd.

str = "hello world"//return: helo wrd

Is it possible?

Thank you!

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

0

Here is one approach. We can first reverse the input string. Then, do a global regex replacement on the following pattern:

(\w)(?=.*\1)

This will strip off any character for which we can find the same character later in the string. But, as we will be running this replacement on the reversed string, this has the actual effect of removing all duplicate letters other than their first occurrence. Finally, we reverse the remaining string again to arrive at the expected output.

var input = "abczacg";
var output = input.split("").reverse().join("").replace(/(\w)(?=.*\1)/g, "");
output = output.split("").reverse().join("");
console.log(output);

about 4 years ago · Juan Pablo Isaza Report

0

An alternative without using a regex using a Set:

[
  "abczacg",
  "aabbccdd",
  "hello world"
].forEach(s => {
  console.log([...new Set(s.split(''))].join(''))
})

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!