Regex for getting texts between Strings

Hello,

I have a text file that i need to extract some information of it

4. CAIXA E EQUIVALENTES DE CAIXA
Descrição 31/12/2021 31/12/2020
Disponibilidades … 10.278 7.742
Aplicações interfinanceiras de liquidez… - 487.380
Total … 10.278 495.122
5. APLICAÇÕES INTERFINANCEIRAS DE LIQUIDEZ
Descrição 31/12/2021 31/12/2020
Aplicações em operações compromissadas … - 487.380
Total … - 487.380
6. TÍTULOS E VALORES MOBILIÁRIOS
O Banco não adota como estratégia de atuação, a aquisição de títulos e valores mobiliários com o propósito de ser
negociados de forma ativa e frequente e também não tem a intenção de mantê-los até o vencimento. Dessa forma, a
carteira de títulos e valores mobiliários foi classificada na categoria “títulos disponíveis para venda” e não houve
reclassificação de categoria entre os períodos apresentados.
A carteira de títulos e valores mobiliários é composta como segue:
31/12/2021
Valores por prazo de vencimento
Valor de Ajuste ao Valor de mercado
Descrição
custo
atualizado
valor de
mercado
Até
360 dias
Acima de
360 dias Total
Letras Financeiras do Tesouro – LFT (i):
Carteira livre … 451.861 (2.462) - 449.399 449.399
Vinculados a operações compromissadas … 47.240 (268) 46.972 - 46.972
Vinculados a garantias … 370 (1) - 369 369
Total … 499.471 (2.731) 46.972 449.768 496.740
(i) As operações são classificadas como Nível 1.
31/12/2020
Valores por prazo de vencimento
Valor de Ajuste ao Valor de mercado
Descrição
custo
atualizado
valor de
mercado
Até
360 dias
Acima de
360 dias Total
Letras Financeiras do Tesouro – LFT (i):
Carteira livre … 362.176 (4.481) - 357.695 357.695
Vinculados a garantias … 354 (1) - 353 353
Total … 362.530 (4.482) - 358.048 358.048
(i) As operações são classificadas como Nível 1.
O valor de mercado dos títulos registrados na categoria “disponíveis para venda” foi apurado com base nas informações
divulgadas pela Associação Brasileira das Entidades dos Mercados Financeiros e de Capitais – ANBIMA e a perda não
realizada para estes títulos no exercício foi de R$ 2.731 (31/12/2020: R$ 4.482), impactando negativamente o patrimônio
líquido do Banco em R$ 1.502 (31/12/2020: R$ 2.465), líquido dos efeitos tributários.

I Nedd the get the info that are inside the Titles (Exemple: Between " 4. CAIXA E EQUIVALENTES DE CAIXA" and " 5. APLICAÇÕES INTERFINANCEIRAS DE LIQUIDEZ") and so on.

Is it possible to do it using regex or any other method?

Hi @luan.quirino1
Try this regex pattern

(?<=4. CAIXA E EQUIVALENTES DE CAIXA)[\s\S]+(?=5. APLICAÇÕES INTERFINANCEIRAS DE LIQUIDEZ)

N

Kindly mark it as solution if it helps

Thanks & Regards,
Nived N

1 Like

Hi, I’ve been using this method.
But, there are other texts I need to get. I actually need it for every text between titles.
I was hoping if there is an expression where I can get the texts for any title (since they are always a digit, a dot, a space and characters in uppercase).

This pattern you gave me works fine, but with it i need to make one for each section of the file.

Regards

@luan.quirino1

Please try this in assign activity…this would give an array of all the string after slpit on numbers

System.Text.RegularExpressions.Regex.Split(url,"(?=^\d+\.)",RegexOptions.Multiline)

Output:

all the 3 are split

What I am checking is if the line starts with a number and a dot together

Hope this helps

cheers

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.