1

This is working

newRow.replace('[[' + key + ']]', item);

but i tried replacing with regex but its not working

newRow.replace('/\[\[' + key + '\]\]/'g, item);
0

1 Answer 1

5

You need to use the RegExp constructor to use the string literal syntax.

newRow.replace(new RegExp('\\[\\[' + key + '\\]\\]', 'g'), item);

Also note that we needed to use \\ instead of \. This is because the \ has its own meaning in string literal syntax. Therefore to get a literal \ character in the string passed to the constructor, we need to escape it.

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

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.