Skip to content

Commit 1ebad96

Browse files
修改正则表达式的常用函数
1 parent c14e991 commit 1ebad96

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

2 常用操作/08-正则表达式.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
console.log(reg.exec(str));// ["sun", index: 0, input: "sun jian feng sunshine studio"]
3939
// match() 根据正则表达式去查找字符串符合规则的内容,返回数组,没有匹配项返回null
4040
console.log(str.match(reg));// ["sun", "jian", "feng"]
41+
// replace()
42+
console.log("sunjianfeng".replace(/jianfeng/,"shine"));//sunshine
43+
// search()
44+
console.log("sunjianfeng".search(/jianfeng/));//3
45+
// split() stringObject.split(separator,howmany) separator为字符串或正则表达式,howmany可选,可指定返回数组的最大长度
46+
console.log("sunjianfeng".split(/n/,3));//["su", "jia", "fe"]
4147

4248
// 比较exec和match
4349
// 1. exec是正则表达式方法,参数为字符串;match是字符串方法,参数为正则表达式

0 commit comments

Comments
 (0)