gpt4 book ai didi

c# - 正则表达式在同一输入上返回不同的结果

转载 作者:太空宇宙 更新时间:2023-11-03 15:04:25 24 4
gpt4 key购买 nike

我正在检查一些结果并传递来自文档的两个输入,两个输入看起来相同但为什么它们返回不同的输出。我的正则表达式是

(?<preandconjunct>(?:\b([Ss]ubsection|[Ss]ection|[Aa]rticle) +)(?<conjunct>(?:(?<level>(?:(?:[IVXivx]{1,5}(?![A-Z]))|(?:[A-Z]{1,2}(?![A-Z]))|(?:[0-9]+)))|(?<level>\((?:(?:[IVXivx]{1,5}(?![A-Z]))|(?:[A-Z]{1,2}(?![A-Z]))|(?:(?!in|or|if|of|to|as|at|it|no|an)[a-z]{1,2}(?![a-z]))|(?:[0-9]+))\))|(?<level>[\.-](?:(?:[IVXivx]{1,5}(?![A-Z]))|(?:[A-Z]{1,2}(?![A-Z]))|(?:[0-9]+))))+)(?=$|[ ,;.)]))

两个输入是

a dispute under Section 3.1 (which shall be governed exclusively by Section 3.1) or as set forth in Section 11.3(b), the indemnification provisions of this Article XI and Article XII are the sole and exclusive remedies of the Parties pursuant to this Agreement or in connection with the transactions contemplated hereby. From and after the Closing, to the maximum extent permitted by Law, except with respect to claims based on intentional fraud, a dispute under Section 3.1 (which shall be governed exclusively by Section 3.1),

a dispute under Section 3.1 (which shall be governed exclusively by Section 3.1) or as set forth in Section 11.3(b), the indemnification provisions of this Article XI and Article XII are the sole and exclusive remedies of the Parties pursuant to this Agreement or in connection with the transactions contemplated hereby. From and after the Closing, to the maximum extent permitted by Law, except with respect to claims based on intentional fraud, a dispute under Section 3.1 (which shall be governed exclusively by Section 3.1),

我也在期待

第 3.1 节

第 3.1 节

第 11.3(b) 节

第十一条

第十二条

第 3.1 节

3.1 节

最后一个没有出现在第一个输入中。

最佳答案

last one is not showing up in first input

获得所有角色的一种方法是消耗最多一个锚定角色。例如,以文本 blah blah Section 3.1(由 Section 3.1 管理) 为例。我们有三个 anchor ,Section()。让我们基于这些文字 anchor 创建一个模式。

我现在要评论我的正则表达式模式,顺便说一下,它需要 IgnorePattnerWhiteSpace 才能在正则表达式解析器中正常工作。

(((Sub)?Section)|Article)\s+    # Anchor of Section or Article or Subsection
(?<Number>[^\s]+) # Number involved
\s+
\( # Anchor of '('
(?<Conjuct>[^)]+) # Consume til next anchor
\) # ')' anchor.

通过使用 Not[^ ] 我们可以使用任何不是结尾的古怪字符 ) anchor 。我们的比赛结果是这样的

enter image description here

why are they returning different output.

您需要通过查看所提到的文字 anchor 来降低捕获的复杂性。甚至可以通过首先创建文本的一般标记并在第二次正则表达式传递时从标记中提取特定项目来执行两次正则表达式?

也像我所做的那样评论你的模式并处理它的各个部分,一旦各个项目起作用就将整个模式组合在一起。

关于c# - 正则表达式在同一输入上返回不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44409692/

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