gpt4 book ai didi

javascript - 匹配 their, their's, theirs, theirs, and their's 的正则表达式

转载 作者:行者123 更新时间:2023-11-30 17:24:52 25 4
gpt4 key购买 nike

我正在尝试将它们和它们的所有格形式与 javascript 中的正则表达式相匹配

到目前为止,我有 their|their(?:'?s),它们匹配 their、theirs 和 their's;但是,不是他们的。

我该怎么做?

所以,他们的他们的他们的他们的应该匹配。

因为theirstheirtheirs'之类的,所以应该匹配较长的。所以如果这个词是 theirs' 它应该匹配那个而不只是 their theirs

他的他的他的他的而不是嘶嘶声呢?

最佳答案

优化正则表达式

起点是这样的:

their|theirs|their's|theirs'

优化后,这会给你:

their(?:s'|'?s)?

their(?:s'?|'s)?

参见 demo 1demo 2 .

第 2 部分:他的|他的|他的而不是嘶嘶声

his(?:'s?)?(?!s)

参见 demo .

关于javascript - 匹配 their, their's, theirs, theirs, and their's 的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24481316/

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