Example Text:
<div id="not-wanted">
no no
no
</div>
<div id="wanted">I want
only this
text
</div> no no no
no no
<div id="not-wanted">
no no no
</div>
<div id="wanted">no no
no no</div>
<div id="wanted">
no no
</div>
需要提供的内容:
I want
only this
text
更好的方法是:
I want only this text
很不幸,我的解决方案也捕捉到了这两个分隔符:
$('#put').append(/<div id="wanted">[^<>]*<\/div>/.exec(strg)[0]);
==>
<div id="wanted">I want
only this
text
</div>
在线示例
问题
如何使用Java Script的正则表达式提取定界字符串之间的字符,并删除其中的\n
和\r
。希望正则表达式的处理速度较快。
strg
中。如何使用它?var txt = strg.getElementById('wanted').innerHTML
不起作用。 - Inherent