JavaScript预定义类
ab+数字+任意字符
ab[0-9][^\r\n] 等价于 ab\d.
'@123@abc@'.replace(/@./g,'Q') Q23Qbc@ 将“@加任意字符”替换为“Q”
'@123@abc@'.replace(/^@./g,'Q') Q23@abc@ 将“以@加任意字符开头的”替换为“Q”
'@123@abc@'.replace(/.@$/g,'Q') @123@abQ 将“以任意字符加@结束的”替换为“Q”
标识符m
var mulSrt = "@123\n@456\n@789"
mulSrt
"@123
@456
@789
"
mulSrt.replace(/@\d/g, "X")
"X23
X56
X89 "
mulSrt.replace(/^@\d/g, "X")
"X23
@456
@789 "
mulSrt.replace(/^@\d/gm, "X")
"X23
X56
X89 "
整理自慕课网教学 点此进入