replace Method Description
Replaces the text found by a regular expression with other text.
Syntax
stringObj.replace(rgExp, replaceText)The replace method syntax has these parts: Part Description
stringObj Required. The String object or literal on which to perform the replace. This object is not modified by the replace method.
rgExp Required. A Regular Expression object describing what to search for.
replaceText Required. A String object or literal containing the text to replace for every successful match of rgExp in stringObj.
Res
The result of the replace method is a copy of stringObj after all replacements have been made.
The method updates the contents of the RegExp object.The following example illustrates the use of the replace method:
function ReplaceDemo()
{
var r, re;
var s = "The quick brown fox jumped over the lazy yellow dog.";
re = /fox/i;
r = s.replace(re, "pig");
return(r);
}
Replaces the text found by a regular expression with other text.
Syntax
stringObj.replace(rgExp, replaceText)The replace method syntax has these parts: Part Description
stringObj Required. The String object or literal on which to perform the replace. This object is not modified by the replace method.
rgExp Required. A Regular Expression object describing what to search for.
replaceText Required. A String object or literal containing the text to replace for every successful match of rgExp in stringObj.
Res
The result of the replace method is a copy of stringObj after all replacements have been made.
The method updates the contents of the RegExp object.The following example illustrates the use of the replace method:
function ReplaceDemo()
{
var r, re;
var s = "The quick brown fox jumped over the lazy yellow dog.";
re = /fox/i;
r = s.replace(re, "pig");
return(r);
}
解决方案 »
- 关于javascript截取字符串的问题
- ext 点击enter键发送消息,不换行
- js时钟无法实现,求解答
- 原生js如何获取#hello input[name=aa[]]数组集?
- 求一正则表达式,可以是数字或者空格
- MAP ABC 经纬坐标定点
- C#windows窗体
- 关于用JavaScript控制网页刷新的问题
- 怎么样改变Frame的大小?
- 同志们,帮个忙吧,要实现在onmouseout,停住一下,可以选择一个选项,怎么实现,代码在下面!
- 求一JS程序:实现在页面上动态随机飘动的一个广告!调试好了,马上给分,还可加分
- 救命!!!如何在一个窗口关闭前要提出确认,如果yes,就关闭窗口,如果no,就不关窗口
var str
str.replace("d","*")将str中的d替换成*
var tmpStr="ababcabcdabcde";
tmpStr=tmpStr.replace(/a/g,"_"); //注释:/g表示全局
alert(tmpStr);
</SCRIPT>