2015-10-28 52 views
0
This is your question? 

[x] Option A 

[ ] Option B 

[x] Option C 

[x] Option D 

[explanation] 

<a href="javascript:void(0);" class="X" >View</a> 

[explanation] 
+2

顯示你的代碼你試過了什麼? –

+0

你能詳細說明你想要做什麼嗎?替換錨(標籤)標籤中的文本?我的意思是文本「查看」 – bozzmob

+1

它會更好地使用JavaScript從DOM中刪除元素,而不是使用正則表達式。如果你還想**使用正則表達式,請使用['/(\[explanation\])[\s\S]+\1/gmi'](https://regex101.com/r/kW8dD8/2 ) – Tushar

回答

0

爲了取代其他兩個字符串(例如,img標籤),請使用此之間的串...

var output = input.replace(/(?:\r\n|\r|\n)/g, '').replace (/\[explanation\](.*?)\[explanation\]/g, "your string replacement"); 
+0

不工作,我想因爲換行 –

+0

這個怎麼樣,更新了答案 – Ehsan

0

找到解決方案 -

var output = input.replace (/(\[explanation\])[\s\S]+\1/gmi, "[explanation]\n\n"+"My New String"+"\n\n[explanation]");