gpt4 book ai didi

javascript - 在不在同一行的两个字符串之间获取一个字符串,正则表达式

转载 作者:行者123 更新时间:2023-11-29 21:06:41 25 4
gpt4 key购买 nike

在 JavaScript 中,我试图获取这两个字符串之间的所有内容但是我想要获取的内容不在同一行中,我是从 api 获取的。

当我打电话时,我得到这个字符串

the 1960s with the release of Letraset sheets containing
Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker
including versions of Lorem Ipsum.

BlogPostStart

the 1960s with the release of L
etraset sheets containing Lorem Ipsum
passages, and more recently with desktop
publishing software like Aldus PageMaker
including versions of Lorem Ipsum.

BlogEnd

基本上,我必须获取 BlogPostStart 和 BlogEnd 之间的所有内容,但不包括这两个词或顶部部分。

我试过这个帖子是来自 api 的整个字符串,基本上是什么:

var blogDescription = post.match(/^(?!\s*(BlogPost|EndBlog)).*/gmi);

但它只是以数组格式返回每一行。

最佳答案

不,React 没有任何东西。它只是普通的旧 JavaScript ......当然还有正则表达式 =)

var string = "the 1960s with the release of Letraset sheets containing <br/>\
Lorem Ipsum passages, and more recently with desktop <br/>\
publishing software like Aldus PageMaker <br/>\
including versions of Lorem Ipsum. <br/>\
<br/>\
BlogPostStart \
\
the 1960s with the release of L <br/>\
etraset sheets containing Lorem Ipsum<br/>\
passages, and more recently with desktop<br/>\
publishing software like Aldus PageMaker <br/>\
including versions of Lorem Ipsum.<br/><br/>\
Mussum Ipsum, cacilds vidis litro abertis. <br/>\
Nullam volutpat risus nec leo commodo, ut interdum diam laoreet. Sed non consequat odio. Quem manda na minha terra sou euzis! Paisis, filhis, espiritis santis. Viva Forevis aptent taciti sociosqu ad litora torquent.<br/>\
<br/>\
BlogEnd";


// REGEX ===============================================================
// =====================================================================
var result = string.match(/(?:BlogPostStart)([\s\S]*)(?:BlogEnd)/)
// =====================================================================
// =====================================================================

document.write(!!result && result[1].trim());

关于javascript - 在不在同一行的两个字符串之间获取一个字符串,正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43728924/

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