replace
"javascript中替换字符串用哪个函数?".replace(/a/g, "A");
"javascript中替换字符串用哪个函数?".replace(/a/g, "A");
解决方案 »
- js 验证
- 后台的新闻编辑器不能自动换行怎么办?
- 推荐几款javaScript的调试工具
- 散分,欢迎下载我的脚本解释器GrayRobot1.3.1~~~
- 能不能通过js控制图片的颜色,比如将图片从红色修改蓝色
- 暴强的免费AJAX,Javascript IDE,大家都来下载
- 关于js一个小程序运行问题
- 一个关于javascript控制图片显示的问题,100分奉送!!!
- 如何让ie浏览器对上边的标题条显示的内容隐藏。在线等,谢谢
- 哪有精减的日历控件下载,或代码贴上,梅花雨你的控件有没有精减版的,现在的太慢了呵,大家帮我,在线等...
- 为什么这个页面显示的文字有些带"?"号?是不是编码问题啊?
- 难难难.在线等
object.replace(regexp, newSubStr)
object.replace(regexp, function)This method is used to match a specifed regular expression against a string and replace any match with a new substring. The newSubStr argument can include certain RegExp properties. These are: $1 thru $9, lastMatch, lastParen, leftContext and rightContext (for details on the RegExp object's properties, go here). To perform a global match include the 'g' (global) flag in the regular expression and to perform a case-insensitive match include the 'i' (ignore case) flag.The second argument can also be a function which is invoked after the match is performed and the result of which is used as the replacement string. The following code uses the replace method to alter 'DevGuru' in the original string to the full URL for the DevGuru website and then uses the String.link method to provide a hyperlink to the site.Code:
myString = new String("Go to DevGuru today!")
rExp = /devguru/gi;
newString = new String ("http://www.devguru.com")
results = myString.replace(rExp, newString.link("http://www.devguru.com"))
document.write(results)Output:
Go to http://www.devguru.com today! 另推荐一个自创的写正则的工具:
http://blog.csdn.net/zhaoxiaoyang
var dd="01";
var cc="0102010201020102";cc.replace(dd,"y");
好象不行啊,只能替换一个,不能全局替换