Saturday, June 1, 2024
 Popular · Latest · Hot · Upcoming
118
rated 0 times [  124] [ 6]  / answers: 1 / hits: 73726  / 8 Years ago, tue, april 5, 2016, 12:00:00

How to replace each occurrence of a string pattern in a string by another string?



var text = azertyazerty;
_.replace(text,az,qu)


return quertyazerty


More From » string

 Answers
15

you have to use the RegExp with global option offered by lodash.



so just use



var text = azertyazerty;
_.replace(text,new RegExp(az,g),qu)


to return quertyquerty


[#62683] Sunday, April 3, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zariahdiamondz

Total Points: 649
Total Questions: 109
Total Answers: 88

Location: Tajikistan
Member since Thu, Apr 14, 2022
2 Years ago
;