Javascript: The global flag with String.replace

     The setup is this; I have some content on a page that needs all pipe characters changed to a newline. However there can be multiple pipes characters in a single body of content. One approach that I used was the global flag in String.replace's method. If you use \g you be warned as the flag is not standardized and you will lose some support for certain browsers. I can't say which ones but I do know that chrome does not support this or whatever version I was using that the time. Not that chrome was my only target browser, just that I took it as a sign for concern. The solution I would use is a regular expression and passed through with a string, much like the example shown in the second link.

JavaScript String replace() Method
 Fastest method to replace all instances of a character in a string - Stack Overflow
replace global flag in Chrome or IE, and how to work around it? - Stack Overflow
regex - How to escape backslash in JavaScript? - Stack Overflow


Popular posts from this blog

Nginx Best Practices Extended

Installing Windows on Acer chromebook 15 cb3-532

Entity Framework: ToListAynsc & WhereAsync