JS RegEx to match all characters (including newline) between two strings but without the two strings?

最后都变了- 提交于 2019-12-05 21:33:40

Now I know how to:

$('#put').append(/<div id="wanted">([\s\S]*?)<\/div>/.exec(strg)[1]);

Thank you Jerry for the (group) hint. [\s\S] stands for every character. *? stop after first found <\/div>.

You can use a capture group and ignore the full match?

$('#put').append(/<div id="wanted">([^<>]*)<\/div>/.exec(strg)[1]);
                                   ^------^                    ^

( ... ) is a capture group and since it's the first one in the regex, it gets to the first capture group, hence the 1 near the end.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!