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

172
Views
evaluate `resin(x)` function in string with regular expression

I am trying to evaluate a function in a string like this resin(8)

so if i have this text 3*(resin(4)-sin(12))

I need to evaluate resin(1) so it will replace that while occurrence with the result which should look like 392.9

I am using this

result = result.replace(/(?<={resin\()(.*?)(?=\)})/, x => parseInt(392.9 * x))

but i need it to replace the resin( part and the ) closing parentheses.

is there any regexp magic I can use?

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

0

Are you sure you need a positive lookbehind and a positive lookahead?

In my opinion, when using a regex replacer, as you did, the grouping is more than enough to accomplish the task:

result = result.replace(/resin\((\d+\.?\d*)\)/g, (_, x) => parseInt(392.9 * parseFloat(x)))

Edit: I just read in your question that you need resin(1) to be replaced with 392.9, but in your snippet you used parseInt and I kept it in my example. Just drop the parseInt in case you don't need the result to be an integer

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!