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

271
Views
javascript regex group why do I get leading blanks?

When matching "product product name cat1" with this regex I get " product name" with a leading blank, of course I could trim in javascript but is there a way to modify regex to not catch that blank ?

(product)((\s+)(.(?!cat1|cat2))+)
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Another way to look at it is to use a non greedy quantifier (.*?) in a single capture group, and match either cat1 or cat2 if you are only interested in product name

\bproduct\s+(.*?)\s+cat[12]\b

Regex demo

about 4 years ago · Juan Pablo Isaza Report

0

You can use

(product)(\s+)((?:(?!cat1|cat2).)+)

See the regex demo.

Note:

  • The tempered greedy token is fixed, see Tempered Greedy Token - What is different about placing the dot before the negative lookahead?
  • The capturing group 2 left boundary is moved after (\s+).
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!