<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>正则表达式 把所有的花引号替换为直引号 把字符串中所有单词的首字母都转换为大写</title>
</head>
<body>
<div id="root"></div>
<script>
//把所有的花引号替换为直引号
let name = '"a", "b"';
let newName = name.replace(/"([^"]*)"/g, "'$1'");
console.log(newName) //'a', 'b'
//把字符串中所有单词的首字母都转换为大写
name = 'aaa bbb ccc';
let uw = name.replace(/w+/g, function(word) {
return word.substring(0, 1).toUpperCase() + word.substring(1);
});
console.log(uw) //Aaa Bbb Ccc
</script>
</body>
</html>