sometext1" ,"title]--6ren">
gpt4 book ai didi

javascript - 有人可以帮我用正则表达式提取文本吗?

转载 作者:行者123 更新时间:2023-11-28 21:15:02 25 4
gpt4 key购买 nike

今天我对正则表达式感到头疼。我无法提取部分文本。我的文字是这样的:

<!--TEXT[title]-->
sometext 1
<!--END-->
<!--TEXT[title]-->
sometext 2
<!--END-->

我想将其放入数组

["title]-->sometext1"
,"title]-->sometext2"]

我有这个正则表达式代码mytext.match(/<!--TEXT[([.|\w|\r|\n]+)<!--END-->/m);

最佳答案

假设您需要正则表达式,以下应该可以工作:

<\!--TEXT\[([^\]]*)\]-->\s*\n(.*)(?!<\!--END-->)

如果此文本位于 DOM 中,那么解析 DOM 会更好。

说明:

<\!--TEXT\[ // Match the start.
([^\]]*) // Match (in group 1), everything up until the next ']'
\]-->\s*\n // Match to the end of this line.
(.*) // Match anything (in group 2).
(?!<\!--END-->) // Stop before the end tag is next. (This will mean you get everything up to, but not including the previous line break).

关于javascript - 有人可以帮我用正则表达式提取文本吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7837443/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com