我有這樣一段代碼使用替換的Javascript替換字符()
<html>
<head>
<title>JavaScript String replace() Method</title>
</head>
<body>
<script type="text/javascript">
var re = /(\w+)\s(\w+)/;
var str = "zara ali";
var newstr = str.replace(re, "$2, $1");
document.write(newstr);
</script>
</body>
</html>
誰能解釋請,這是什麼,它是如何看?
var re = /(\w+)\s(\w+)/;
而且在str.replace(re, "$2,$1);
,什麼是港幣$ 16 & $ 1嗎?
查找有關正則表達式的教程。 – elclanrs
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Regular_Expressions – j08691
你在那個變量裏看到的是一個正則表達式。一個簡單的谷歌搜索應該告訴你很多。 – SarathChandra