Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda