![](/img/trans.png)
[英]javascript regex, replace multiple instances with a single one in multiline string
[英]JS Regex - Replace multiple instances in a string
我有這個字符串:
var str = '"testFN, II testLN, II" < test1@test.com>, "testFN, Cal testLN, Cal" < test2@test.com>';
我在做
str.replace(/(".*?),(.*?")/g, '$1__comma_$2');
僅在“”內用字符串(__comma_)替換多個逗號(,)。
事件雖然我給/ g它不替換所有實例。 它僅替換每個實例的第一個匹配項。
實際結果:“ testFN__comma_ II testLN,II” <test1@test.com>,“ testFN__comma_ testLN,Cal” <test2@test.com>預期結果:“ testFN__comma_ II testLN__comma_ II” <test1@test.com>,“ testFN__comma_ Cal testLN__comma_ Cal“ <test2@test.com>
你能給我一些什么我想念的建議嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.