我一直在尋找PHP preg_replace
函數的js等價物,而我到目前爲止發現的僅僅是string.replace
。JavaScript的等效PHP preg_replace
但是我不知道如何將我的正則表達式轉換爲JavaScript。這是我的PHP代碼:
preg_replace("/()*/", $str, $str);
因此,例如以下:
test test test test
變爲:
test-test-test-test
任何人都知道我怎麼能在JavaScript這樣做呢?
工程就像一個魅力,謝謝! – Skyfe