<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
var str1 = 'php php';
var r1 = /h/g;
var result1 = str1.replace(r1, 'H');
console.log(result1);
var str2 = 'php7 and ES5';
var r2 = /(d)/g;
var result2 = str2.replace(r2, '$1$1');
console.log(result2);
var str3 = 'nba';
var result3 = str3.replace(/(b)/g, "[$`-$1-$']");
console.log(result3);
var str = 'aaa bbb ccc';
var result = str.replace(/[a-z]+/g, function(x){
return x.substr(0,1).toUpperCase() + x.substr(1);
});
console.log(result);
</script>
</body>
</html>