var ss= "<pre>aaaa
bbb
ccc</pre>ddd";
var arr= ss.match( /<pre.*?</pre>/gm );
alert(arr); // null
I'd want the PRE block be picked up, even though it spans over newline characters.
(我希望可以拾取PRE块,即使它跨越换行符也是如此。)
I thought the 'm' flag does it.(我以为'm'标志可以做到。)
Does not.(才不是。)
Found the answer here before posting.
(发布前在这里找到答案。)
SInce I thought I knew JavaScript (read three books, worked hours) and there wasn't an existing solution at SO, I'll dare to post anyways.(因为我以为我知道JavaScript(读了三本书,花了很多时间),所以SO上没有现有的解决方案,所以无论如何我都敢发表。)
throw stones here(在这里扔石头)
So the solution is:
(因此解决方案是:)
var ss= "<pre>aaaa
bbb
ccc</pre>ddd";
var arr= ss.match( /<pre[sS]*?</pre>/gm );
alert(arr); // <pre>...</pre> :)
Does anyone have a less cryptic way?
(有谁有一个不太神秘的方式?)
Edit: this is a duplicate but since it's harder to find than mine, I don't remove.
(编辑: 这是重复的,但是由于它比我的更难找到,因此我不会删除。)
It proposes [^]
as a "multiline dot".
(它建议[^]
作为“多行点”。)
What I still don't understand is why [.\n]
does not work.(我仍然不明白是为什么[.\n]
不起作用。)
Guess this is one of the sad parts of JavaScript..(猜猜这是JavaScript的不幸部分之一。)
ask by akauppi translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…