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

134
Views
How can I use regex to get matches on each side of the equal sign for the string (test1)=(tes=)t2)

I need to capture two matches between an equal sign: (test1)=(test2) such that match1 = test1 and match2 = test2. So far I have been able to use /\([\s\S\)\(]*?\)/gmi which mostly works UNLESS there is an additional close paren on either side of the equal sign, ie: (test1)=(te)st2).

What regex could I create that would allow me to successfully wind up with two matches given the below:

"(test1)=(tes=)t2)".match( /\([\s\S\)\(]*?\)/gmi ) === ["test1", "tes=)t2"]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

For the examples in the question and if supported using lookarounds, you can assert that the closing parenthesis can not contain = or ) to the right.

Note that you can omit the /m flag as there are no anchors in the pattern, and you can also omit the /i flag as the pattern does not specifically matches upper or lowercase characters.

let regex = /(?<=\().*?(?=\)(?![^\s=)]))/g;
let str = "(test1)=(tes=)t2)";
console.log(str.match(regex));

Or using a capture group without a lookbehind assertion:

let regex = /\((.*?)\)(?![^\s=])/g;
let str = "(test1)=(tes=)t2)";
const result = Array.from(str.matchAll(regex), m => m[1]);
console.log(JSON.stringify(result) === JSON.stringify(["test1", "tes=)t2"]));

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!