最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JavaScript 中的replace方法說明

 更新時(shí)間:2007年04月13日 00:00:00   作者:  
第一次發(fā)現(xiàn)JavaScript中replace() 方法如果直接用str.replace("-","!") 只會(huì)替換第一個(gè)匹配的字符.  
而str.replace(/\-/g,"!")則可以替換掉全部匹配的字符(g為全局標(biāo)志)。  

replace()  
The replace() method returns the string that results when you replace text matching its first argument  
(a regular expression) with the text of the second argument (a string).  
If the g (global) flag is not set in the regular expression declaration, this method replaces only the first  
occurrence of the pattern. For example,  

var s = "Hello. Regexps are fun.";s = s.replace(/\./, "!"); // replace first period with an exclamation pointalert(s); 

produces the string “Hello! Regexps are fun.” Including the g flag will cause the interpreter to  
perform a global replace, finding and replacing every matching substring. For example,  

var s = "Hello. Regexps are fun.";s = s.replace(/\./g, "!"); // replace all periods with exclamation pointsalert(s); 

yields this result: “Hello! Regexps are fun!”  

相關(guān)文章

最新評(píng)論

颍上县| 寻甸| 安化县| 商丘市| 秦安县| 句容市| 玉山县| 广安市| 库伦旗| 金山区| 巴里| 铜鼓县| 鹤庆县| 明光市| 普格县| 马公市| 云南省| 曲水县| 白银市| 洪泽县| 涞源县| 清水河县| 青田县| 盖州市| 宣汉县| 六枝特区| 乐至县| 福清市| 江陵县| 韩城市| 京山县| 黑河市| 高要市| 衡阳县| 东兰县| 于都县| 东安县| 那曲县| 许昌县| 黄冈市| 高尔夫|