2020面试准备12----如何把一个字符串的大小写取反(大写变小写或小写变大写)

let str = "adsfsgEREvg啦啦啦啦啦dfsfr";
str = str.replace(/[a-zA-Z]/g,content=>{
	console.log(content)
	// content=>每一次正则匹配的结果
	return content.toUpperCase()===content?content.toLowerCase():content.toUpperCase()
})
console.log(str)//=>ADSFSGereVG啦啦啦啦啦DFSFR
发布了23 篇原创文章 · 获赞 0 · 访问量 989

猜你喜欢

转载自blog.csdn.net/yangling_123/article/details/104872973