Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda