gpt4 book ai didi

正则表达式停止搜索特定字符串

转载 作者:行者123 更新时间:2023-12-05 03:14:11 24 4
gpt4 key购买 nike

我试图在重复特定模式后获取任何字符,但我需要在特定字符串处停止搜索。例如:

anything anything anything:"pattern":"string" anything anything anything "pattern":"another_string" specific string anything anything anything

所以我需要在特定字符串处停止正则表达式

我有这个正则表达式:

/pattern":"(?<data>.+?(?="))/

所以结果会是:

Match 1: data = **string**; 
Match 2: data = **another_string**

但它不会停止在特定字符串

我试过这个正则表达式,但它不起作用:

/pattern":"(?<data>.+?(?=")).+specific string/

最佳答案

您需要使用前瞻来断言“特定字符串”位于字符串中的某处。

/pattern":"(?<data>.+?)"(?=.+specific string)/si

关于正则表达式停止搜索特定字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26495583/

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