DEV Community

ivkeMilioner
ivkeMilioner

Posted on • Updated on

How to call strings from json file?

How to call strings from json for this code?

entered_text.replace(/STRING_ONE/g,"STRING_ONE");

Top comments (2)

Collapse
 
taufik_nurrohman profile image
Taufik Nurrohman

I assume that the first STRING_ONE is a variable contains another string.

entered_text.replace(new RegExp(STRING_ONE, 'g'), 'STRING_ONE');

PS: Make sure to double escape the \ characters in STRING_ONE as you are putting regex pattern from string. So, for example, ^[a-z\d-]+$ must be written as ^[a-z\\d-]+$.

Collapse
 
ivkemilioner profile image
ivkeMilioner

STRING_TWO replace word or words from STRING_ONE

But i have too many word to replace.