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

154
Views
Finding consecutive characters but ignore space & case?

I'm looking to match the following strings so that I can later truncate them from the string in JS. For ex: matched: i like eeeting pie and a a a a a bananas. matched: My name iIIs John Doe and A a A a AA AAA I'm cool.

This is the regex I currently have, but it doesn't match if there is a space in between or if there are more than 3 consecutive letters:

(.)\1\1
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use

/(\S)(?:\s*\1){2,}/gi
/\b(\S)(?:\s*\1){2,}/gi

If you need to make sure you only start matching at the word boundary, you need to use the second regex.

See the JavaScript demo:

const text = "i like eeeting pie and a a a a a bananas. My name iIIs John Doe and A a A a AA AAA I'm cool.";
const re = /(\S)(?:\s*\1){2,}/gi;
document.body.innerHTML = text.replace(re, '<b>$&</b>')
// Second regex demo:
document.body.innerHTML += "<br/>" + text.replace(/\b(\S)(?:\s*\1){2,}/gi, '<b>$&</b>')

The regex has the i case insensitive flag and matches

  • (\S) - Group 1: any non-whitespace char
  • (?:\s*\1){2,} - two or more occurrences of
    • \s* - zero or more whitespaces
    • \1 - the value of Group 1.

See the regex scheme:

enter image description here

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!