Javascript或JQuery删除之间的某些文本和字符

时间:2017-08-17 01:09:47

标签: javascript jquery

我有这样的HTML:

<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>

介于两者之间的一切都必须要去。

3 个答案:

答案 0 :(得分:0)

据我了解,这应该适合你。演示网址:http://regexr.com/3gioj

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

答案 1 :(得分: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 )

甚至不需要RegEx。然后只需将句子附加到你想要的地方

答案 2 :(得分:0)

这是一个使用正则表达式删除For).的所有内容的代码段。

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

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