0

I have the following string:

Are you sure you want to delete "%lg_name%" group?

And in Javascript I have the variable lg_name. How can I replace lg_name string to lg_name variable? This regex shouldn't be related to the variable name. Thanks.

0

3 Answers 3

1
'Are you sure you "%lg_name%" group?'.replace(/"%[^"%]*%"/, 'value');

Basically, you should find the "%variable_name%" token. You can do that using /"%[^"%]*%"/ pattern. Then you can simply replace it, using the replace method of the your string.

Sign up to request clarification or add additional context in comments.

Comments

1

Here is your solution, it replace the corresponding %lg_name% part with the variable name lg_name

'Are you sure you "%lg_name%" group?'.replace(/"%([^"%]*)%"/, function ($1,$2){return $2});
>>"Are you sure you lg_name group?"

Comments

1
   '11111'+(new RegExp("[a-z0-9]*"+lg_name+"[a-z0-9]*",'gi')).exec("Watch out for the rock!")[0]+'22222'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.