dragos Posted on Dec 4, 2019 • Edited on Dec 10, 2019 How to call strings from json file? #javascript #json How to call strings from json for this code? entered_text.replace(/STRING_ONE/g,"STRING_ONE"); Top comments (2) Subscribe Submit Preview Dismiss Collapse Expand Taufik Nurrohman Taufik Nurrohman Taufik Nurrohman Follow I have a dream, but it won’t make me rich. Location Banyumas, Indonesia Education Self taught. Work Registered Nurse Joined Jun 20, 2019 • Dec 5 '19 Dropdown menu Copy link Hide 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 Expand dragos dragos dragos Follow Indie app builder focused on simple, practical products. Currently building Vet Record, a pet health tracker for everyday owners. Location Beograd Education Completed an online course by Carnegie Mellon University Joined Oct 15, 2019 • Dec 5 '19 Dropdown menu Copy link Hide STRING_TWO replace word or words from STRING_ONE But i have too many word to replace. Code of Conduct • Report abuse
Top comments (2)
I assume that the first
STRING_ONEis a variable contains another string.PS: Make sure to double escape the
\characters inSTRING_ONEas you are putting regex pattern from string. So, for example,^[a-z\d-]+$must be written as^[a-z\\d-]+$.STRING_TWO replace word or words from STRING_ONE
But i have too many word to replace.