Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
13
rated 0 times [  15] [ 2]  / answers: 1 / hits: 110614  / 15 Years ago, thu, july 30, 2009, 12:00:00

Why is the '/g' required when using string replace in JavaScript?



e.g. var myString = myString.replace(/%0D%0A/g,<br />);


More From » javascript

 Answers
119

It isn't required, but by default string.replace in JavaScript will only replace the first matching value it finds. Adding the /g will mean that all of the matching values are replaced.


[#99028] Sunday, July 26, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
charlesmarions

Total Points: 310
Total Questions: 96
Total Answers: 107

Location: Netherlands
Member since Wed, Feb 8, 2023
1 Year ago
;