Python 正则表达式。在匹配问题之间捕获文本
Python Regex. Capturing text between matches issue
刚接触正则表达式,无法正确匹配。
我有以下字符串:
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})
如果将 (at)(?!.*at)(.*)
与 s 标志一起使用,则只有最后一个 at
而不是前面的另一个 at
。所以预计只有最后一个会匹配。 (at)((?:(?!at).)*)
不会跳过另一个 at
。
刚接触正则表达式,无法正确匹配。
我有以下字符串:
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})
如果将 (at)(?!.*at)(.*)
与 s 标志一起使用,则只有最后一个 at
而不是前面的另一个 at
。所以预计只有最后一个会匹配。 (at)((?:(?!at).)*)
不会跳过另一个 at
。