replace() 替换
来源:互联网 发布:烟台新天宇软件 编辑:程序博客网 时间:2024/05/19 01:10
用于在字符串中用一些字符替换另一些字符,或替换一个与正则表达式匹配的子串
var str ='abcdefg';var n =str.replace(/b/, "2");console.log(n);
输出结果 a2cdefg
全局替换
var str="Welcome to Microsoft! "str=str +'\n'+ "We are proud to announce that Microsoft has "str=str +'\n'+ "one of the largest Web Developers sites in the world."var n =str.replace(/Microsoft/g, "ITeye");console.log(n);
输出结果
Welcome to ITeye!
We are proud to announce that ITeye has
one of the largest Web Developers sites in the world.
将字符串中所有单词的首字母都转换为大写
var str = 'hello world';str = str.replace(/\b\w+\b/g, function(word){return word.substring(0,1).toUpperCase()+word.substring(1);});
输出结果"Hello World"
将'world, hello'变为'hello world'
n = "World, Hello";n.replace(/(\w+)\s*, \s*(\w+)/, "$2 $1");
逗号后面有空格
0 0
- 替换(replace)
- replace替换
- replace() 替换
- 字符串替换,不用replace
- javascript replace 替换空格
- replace替换用法
- js replace 替换
- Replace替换 " 符号
- js replace 全部替换
- js 替换所有(replace)
- replace替换符
- replace替换字符串问题
- replace 替换字符串。
- JQuery replace字符串替换
- oracle 字符替换 replace
- [js]replace替换
- SQL replace 替换
- js replace 字符串替换
- 增加代码可读性——注释篇
- DEDECMS所有标签调用方式大全
- dao层与service层傻傻分不清楚
- 仪表盘 网速测试 自定义view
- split()分割字符串
- replace() 替换
- PHP实现各种经典算法
- Mysql和Java数据类型对比一览表
- 入门Webpack,看这篇就够了
- js构造器
- python+TCP/UDP
- html5
- HDU 4430 Yukari's Birthday 二分
- css基础