2017-03-22 44 views
-1

我想用組合*whitespace*[w OR i]替換組合*whitespace*[w OR i]中的每個空格,並使用Javascript和RegEx編號0只匹配特定字符後的空格

例子:

這句話:

Somethingi i somethingw else w another thing.

應該是這樣的:

Somethingi i0somethingw else w0another thing.

我知道,在正則表達式是一樣的東西look behind它會來方便但不幸只是,這不適用於JavaScipt的RegEx版本。我正在尋找特定的RegEx公式或聰明的方式來做到這一點在JS中。

+0

能不能請你告訴你嘗試過什麼? –

+0

謝謝你的回覆。以下是我的問題的正確答案。 – SuperM4n

回答

0

使用這個表達式:

(\s[iw])\s 

$10取代。

演示:https://regex101.com/r/5ULjU7/2

console.log("Somethingi i somethingw else w another thing.".replace(/(\s[iw])\s/g, '$10'));

+0

非常感謝!這對我來說可以! – SuperM4n

相關問題