gpt4 book ai didi

Regex lookbehind - 从搜索中排除单词

转载 作者:行者123 更新时间:2023-12-01 13:32:21 25 4
gpt4 key购买 nike

我需要在我的语料库中搜索诸如gameshame 之类的词,但我想指定搜索以排除三个字符串 a game/a shame or , A game/A shame and a/an/A/An WORD gamea/an/A/An WORD shame ,其中 WORD 是一个修饰语,例如,一个伟大的游戏一个伟大的耻辱

如果有人能帮助我,那就太好了,谢谢!

在我的语料库中,不定冠词 a/angamea/anshame< 之间的可选词/em> 最常见的是伟大真实。所以即使排除这两个,也会对我有很大帮助。

下面的 lookbehind 可以完美地排除 a/A

(?<!a\s|A\s)\bshame\b

为了排除修改 WORD,我试图在 lookbehind grep 中使用 ?\w,但它只是行不通 - 下面没有 ? 的 grep 运行并且它仍然排除示例,例如a shame,但它仍然返回不需要的示例,例如 a great shamea crying shame - 参见索引行 (3) 和 (4) ) 在下面的示例文本中:

    (?<!a\s|A\s|a\b\w\b|A\b\w\b)\bshame\b

我用来实现正则表达式的工具是 AntConc,它支持 Perl 正则表达式。

使用下面的搜索字符串后带有两个不相关示例(3 和 4)的示例文本

(?<!a\s|A\s)\bshame\b

1(匹配耻辱)

, people ogling from the sidelines.&nbsp; If you want a closer look, you have to ring for entry and wait to be admitted.&nbsp; I guess me and Saul just have no shame (or just know the benefits of our bank accounts being in hard currencies), because we wandered into plenty.&nbsp; Lots and lots of little boutiques and edgily designed fashion stores with music blaring.& abbutterflie.txt 47 1

2(匹配耻辱)

last twenty years and I've experienced all sorts of biggotry but I seriously thought that anti black nazism in football wass a thing of the past. You should all hang your heads in shame, bunch of [badword]s. adamdphillips.txt 57 1

3(不匹配羞耻)

me monetarily as I wasn't that close to her, but she was really good friends with the other girl and it's messed that up for them a bit, which is a great shame. Anyway, Holly and I have since found somewhere to move in just the two of us. It's going to cost an absolute fortune and I'm going to be eating basics beans on aderyn.txt 60 1

4(不匹配羞耻)

are loads of amazingly good bands out there, gigging up and down the country who will never get signed because no-one can figure out how to market them, and this is a crying shame. There are artists out there like <a href="http://www.angelsintheabattoir.com/" rel="nofollow">Thea Gilmore</a> and <a href="http://blog.amandapalmer.net/" rel="nofollow"> Amanda Palmer& aderyn.txt 60 2

5(匹配耻辱)

/><br />"There is no better time to show these terrorists that we have no fear of them. Instead we are forced, through the cowardly acts of our superiors, to hide in shame."<br /><br />But Herb Wiseman, high school consultant for Lee County, Florida, pointed to the July 7 London bombings.<br /><br />"What happens if kids get on aggy91.txt 64 1

最佳答案

因为不允许可变长度的负后视,所以您上一个问题的答案中的方法不会转移到这个问题。

我使用了 (*SKIP)(*FAIL) 模式。这将匹配并丢弃不合格的匹配,并且只保留合格的匹配:

/[Aa]n?(\w+)?羞耻(*跳过)(*失败)|羞耻/ 3844 步 ( Demo )

或者如果您希望包含单词边界元字符:

/\b[Aa]n?(\w+)? shame\b(*SKIP)(*FAIL)|\bshame\b/ 4762 步 ( Demo )

关于Regex lookbehind - 从搜索中排除单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45197080/

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