Multiple simultaneous Places with javascript

Asked

Viewed 48 times

0

How I can do multiple simultaneous Places without having to do one by one?

Example: I have a formula, in a string format, whose image follows immediately below.

inserir a descrição da imagem aqui

I have already calculated all these values and I have to replace these calculated values in USERS.

There’s a way instead formula = formula.replace(totalUsers,"USERS"); one by one, do all these values simultaneously?

  • 1

    Put the text, n]to the image. And explain better what you want. It’s very generic. Replace what with what? Put it like you’re gonna do it one by one.

  • The idea is to be really Generic

  • Gabriel still agree with @bigown that you can give a clearer, text-coded example.

  • Trying to help: It’s something like this you need in your regex? USERS|OPTIONS|MFPCONNECTOR|GATEWAY|HARDWARESOFTWARE|HARDWAREGATEWAY... See here: http://regexr.com/3gps4

1 answer

2

replace the first time only if you receive a String as first argument. If you use a regex with falg g replaces everyone you meet. I think that’s what you’re looking for:

const regex = new RegExp(totalUsers, 'g'); // g é para multiplas ocurrências
formula = formula.replace(regex, "USERS");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.