gpt4 book ai didi

regex - Python正则表达式。在匹配问题之间捕获文本

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

正则表达式非常新,并且无法获得正确的匹配。
我有以下字符串:

The AGM will be held at the Company's registered office at Unity House, Telford Road, Basingstoke, Hampshire, RG21 6YJ on 13 January 2016 at 10.00 a.m.

The Company announces that its 2016 Annual General Meeting will be held on 11 February 2016 at 10.00 a.m. at Hangar 89, London Luton Airport, Luton, Bedfordshire, LU2 9PF.


我试图从最后一次出现的 'at' 中提取地址,直到邮政编码。 So Unity House, Telford Road, Basingstoke, Hampshire, RG21 6YJ and Hangar 89, London Luton Airport, Luton, Bedfordshire, LU2 9PF
这是我用的 (at)(?!.*at)(.*)\s([A-Z]{1,2}[0-9][A-Z0-9]? [0-9][ABD-HJLNP-UW-Z]{2})它只提取第二个地址。有什么想法吗?
谢谢

最佳答案

看起来您要使用 ((?:(?!at).)*)相反 (?!.*at)(.*)避免跳过 at

(at)((?:(?!at).)*)\s([A-Z]{1,2}[0-9][A-Z0-9]? [0-9][ABD-HJLNP-UW-Z]{2})

See demo at regex101

如果您使用 (at)(?!.*at)(.*)带有 s 标志,只有最后一个 at不是另一个 at先。所以预计只有最后一个会匹配。 (at)((?:(?!at).)*)不会跳过另一个 at .

关于regex - Python正则表达式。在匹配问题之间捕获文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35137436/

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