حالا اینو امتحان کنید
کد HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style></style>
</head>
<body>
<textarea id='txt1'></textarea>
<button onclick='replaceWords()'>نمایش</button>
<textarea id='txt2'></textarea>
<script>
var changes = {
'[fars]': 'pars'
}
function replaceWords () {
var replaceString = document.getElementById('txt1').value;
for (var word in changes) {
var wrd = word.replace("[", "\\[").replace("]", "\\]");
replaceString = replaceString.replace(new RegExp(wrd, 'g'), changes[word]);
}
document.getElementById('txt2').value = replaceString;
}
</script>
</body>
</html>