gpt4 book ai didi

如果字符串未夹在两个标记之间则要匹配的正则表达式

转载 作者:行者123 更新时间:2023-12-02 01:46:15 26 4
gpt4 key购买 nike

我在使用正则表达式时遇到问题。本质上,我想匹配一个字符串,前提是开头和结尾之间没有特定的字符串。让我澄清一下,排除字符串 (123)、开头 (hello) 和结尾 (abc):

hello123abc   ==> no match
helloa123abc ==> no match
hello123aabc ==> no match
helloa123aabc ==> no match
hello1abc ==> match
hello23abc ==> match
helloaabc ==> match
helloabc ==> match

我有一个骨架框架:

=~ m/hello___abc

并尝试用以下所有内容填空:

(?!123).*?
.*?(?!123)
.*?(?!123).*?
(?!123)
(?!123)*?
.*?[^1][^2][^3].*?

还有一些我不记得的其他组合,但都没有奏效。有没有人有办法做到这一点?

最佳答案

在这里你可以使用 PCRE 动词 (*SKIP)(*F),

(?:hello.*?123.*?abc)(*SKIP)(*F)|hello.*?abc

DEMO

(?:hello(?:(?!hello).)*123.*?abc)(*SKIP)(*F)|hello.*?abc

DEMO

关于如果字符串未夹在两个标记之间则要匹配的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25540338/

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