You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

正则表达式特定分组捕获问题:提取逗号与句号间内容

正则表达式匹配优化方案

待匹配数据格式

430::1820-07-27::Vitorino Pinheiro Lacerda::Rodrigo Pinheiro Lacerda::Custodia Maria Alvares::::
430::1873-05-12::Vitorino Teixeira Pires::Jose Teixeira::Ana Martins Pires::Doc.danificado.::
425::1724-09-06::Xavier Araujo Costa::Bernardo Araujo::Angela Costa::::
425::1714-07-30::Xavier Araujo Ferreira::Geraldo Araujo::Ana Ferreira::Jose Araujo Ferreira,Irmao. Proc.21011.::
425::1689-11-02::Xisto Magalhaes Cunha::Francisco Fernandes::Maria Francisca::Doc.danificado.::
426::1898-11-18::Zacarias Rodrigues Mano::Manuel Rodrigues Mano::Felicidade Jesus Tarrio::::
426::1900-11-12::Zacarias Silva Mariz::Luis Silva Mariz::Felicidade Correia Santos::::
426::1785-10-20::Zeferino Antonio Pereira Nobre::Antonio Pereira Nobre::Maria Josefa Garcia::::
425::1809-01-27::Zeferino Antonio Vassalo::Simao Vassalo::Maria Jose::::

当前问题

已能捕获folder、date、name、father、mother、observations等分组,但无法精准捕获逗号到下一个句号之间的内容(例如第四行中的Irmao)。

当前使用的正则表达式:

(?P<folder>\d*)::(?P<date>\d{4}-\d{2}-\d{2})::(?P<name>.+?)::(?P<father>.+?)::(?P<mother>.+?)::(?P<observations>.*((?:,)?(?P<family>[^\.]*)?))(?:::)?

修正后的正则表达式

(?P<folder>\d*)::(?P<date>\d{4}-\d{2}-\d{2})::(?P<name>.+?)::(?P<father>.+?)::(?P<mother>.+?)::(?P<observations>.*?(?:,(?P<family>[^.]+)\.)?)?(?:::)?

关键调整说明

  • 对observations分组使用.*?非贪婪匹配,避免过度匹配覆盖后续目标内容
  • 精准定位逗号+目标内容+句号的结构:(?:,(?P<family>[^.]+)\.)?,其中
    • (?:...)为非捕获组,用于包裹可选的匹配结构,不额外生成分组
    • (?P<family>[^.]+)精准捕获逗号后到下一个句号前的所有非句号字符,确保只获取目标内容(如Irmao)
    • 整个结构末尾加?,适配无该内容的行(如大部分无逗号句号的条目)

内容的提问来源于stack exchange,提问作者Braz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 00:12:59