我有三個工作正則表達式的替換字符串,正則表達式用字和字符
string.replace(\catalogue\g, "") // replace a the word catalogue
string.replace(/[/:]/g, "") // replace the characters /, :
string.replace(\20%\g, "") // replace '20%'
,而不是替換字符串三次,我想結合我的正則表達式的。
想要的結果='removethewordnow';
var string = 'rem:ove20%the/word:catalogue20%now';
我最新的嘗試是:
string.replace(/\catalogue\b|[/20%:]/g, ""); // works, but catalouge is unaffected and 20% isn't combined as a word
我可能是錯的,但我覺得你錯過了一個「或」(|)語句 – SpYk3HH 2012-03-05 14:37:50
它的B之後右 - B | [*字母*] – patad 2012-03-05 14:38:59
我並沒有故意逃離c,只是整個單詞「目錄」 - 但第一個實際上工作得很好。 – patad 2012-03-05 14:50:07