替换字符串中的所有匹配项 [英] replace all occurrences in a string
本文介绍了替换字符串中的所有匹配项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
最快的方法来替换字符串中字符的所有实例
如何替换字符串中的所有匹配项?
How can you replace all occurrences found in a string?
如果要替换所有换行符字符串中的字符(\ n)..
If you want to replace all the newline characters (\n) in a string..
这只会替换第一次出现的换行符
This will only replace the first occurrence of newline
str.replace(/\\n/, '<br />');
我无法弄清楚如何做到这一点?
I cant figure out how to do the trick?
推荐答案
使用全局标记。
str.replace(/\n/g, '<br />');
这篇关于替换字符串中的所有匹配项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文