2017-08-17 72 views
0

之間我有HTML像這樣:Javascript或jQuery來刪除某些文字及字符

<br> 
For the application these are [a bunch of random characters that need to be removed]). 
<br? 
<br> 

我需要使用JavaScript/JQuery的(可能是一個正則表達式)除去HTML開始:

For the application these are 

和結尾:在兩者之間必須走得太

). 
<br> 
<br> 

一切。

+0

你需要有專門針對這句話,還是會沒關係從容器中取出保存的內容的任何文本? –

+0

document.body.innerHTML ='
\ r \ n'; 不太清楚你要問什麼,但是這應該會讓你只在頁面上的第一個
,因爲一切都必須刪除。 – OwChallie

+0

這句話需要有針對性。這應該是正則表達式的起點,然後在 – cdub

回答

0

這是一個片段,使用正則表達式從For).刪除所有內容。

document.body.innerHTML = document.body.innerHTML.replace(/For(.*?)\)\./,''); 
 

 
console.log(document.body.innerHTML);
<br> 
 
For the application these are (sdi12ni3jo45n). 
 
<br> 
 
<br>

0

據我瞭解,這應該適合你。演示網址:http://regexr.com/3gioj

$(your_element).replace(/For the application these are .+?(\)\.)/g,"") 
+0

之上的終點這個正則表達式在某種程度上是錯誤的 – cdub

0

如果字和字符準確,在所有情況下確切的100%,則易:

var sentence = "For the application these are foofoofoo!!!)" 

sentence = sentence.replace(sentence.split("For the application these are ")[1].split(")")[0], ""); 

console.log(sentence); 

//output: For the application these are) 

甚至不需要正則表達式。然後只是追加句子到任何你想要的地方

+0

這不回答OP的問題。注意:「之間的一切都必須去。」 –

+0

我不會在語法上得到「兩者之間的一切都必須去。」 – Merigold

+0

換句話說,「'For'」和「').'」以及它們之間的所有字符都應從頁面中刪除。 –