1

I'm trying to develop a regular expression that matches data with this format:

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::::

For now, I managed to obtain most of the specific groups however I am struggling to obtain an expression to obtain a group that captures the content between a "," and the next occurrence of a ".". An example can be the fourth case previously presented where the content that should be captured is "Irmao".

Here's the regular expression I obtained so far:

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

3
  • 1
    Do you have to use regex? Your task would be much simpler if you split the lines by :: and then tried regex for only the observations part.
    – pho
    Mar 4 at 1:50
  • Please include the output groups you want here. Mar 4 at 2:20
  • @PranavHosangadi really good alternative however regex use was mandatory for all the expression.
    – Braz
    Mar 4 at 12:17

1 Answer 1

1

In the named group observations, you can optionally match a comma, then any char except a comma or dot until you match the first dot.

(?P<observations>[^,\n]*(?:,(?P<family>[^,.\n]*)\.)?.*)::

The full pattern:

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

Regex demo

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.