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
REGEX How can I check if a string has more than 2 spaces in it?

I am trying to regex (ECMAscript) check if a string has three or more spaces in it. Essentially, I want the minimum number of spaces to be 3 before it matches. Here are some examples;

"Microsoft and Apple" This would NOT match

"The quick brown fox" This WOULD match

"lots of spaces in this sentence" This WOULD match

This is the best I have so far;


/[\s]{3,}/gm


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

0

If the 'string' can contain everything (characters and numbers and special chars):

/^((.*?)? (.*?)?){3,}?$/gm
about 4 years ago · Juan Pablo Isaza Report

0

This may not be optimally efficient, but you could split on spaces and then check the resulting length:

const x = [
 "Microsoft and Apple",
 "The quick brown fox",
 "lots of spaces in this sentence",
]

x.forEach(s => console.log(s, s.split(' ').length > 3))

about 4 years ago · Juan Pablo Isaza Report

0

Put three spaces in the regex, and match anything else around them

.* .* .* .*

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!