Find all occurrences in a document or big string

Hi friends

How do I find all occurrences of a specific text in a big string (Document with line break or String with line break, and concatenate all the occurrences together (array)?

For example:

I have a column with text extracted from a PDF.
There are various line breaks.

I need to find all occurrences of the term “Referência:” and if I find it, I need to get the next 8 characters.

Text Example - For using in node

Informações do 1º Arquivo ______________________________

Referência: 05/2018
Nome do arquivo .txt: 44708379000999_201805.txt
Versão do leiaute: 1.0.0
Finalidade:
Hash do arquivo .txt:
8803015cae6e066a2b84

Informações da Transmissão

Protocolo TED: 00009100
Data da transmissão: 22/02/2019 17:19:15

Informações do Processamento

Nº Identificador: 00055253
Data de processamento: 10/04/2019 22:46:06
Situação:

Informações do 2º Arquivo ______________________________

Referência: 06/2018
Nome do arquivo .txt: 44708379000999_201806.txt
Versão do leiaute: 1.0.0
Finalidade:
Hash do arquivo .txt:
a7c810bc5a3856396859c76813589572652eb50f9e60091daaa58f6bd3808412
0227ca30592d0c6526dd2f68

Informações da Transmissão

Protocolo TED: 00009101
Data da transmissão: 22/02/2019 17:19:31

Informações do Processamento

Nº Identificador: 00055254
Data de processamento: 10/04/2019 22:46:17
Situação:

Informações do 3º Arquivo ______________________________

Referência: 07/2018
Nome do arquivo .txt: 44708379000999_201807.txt
Versão do leiaute: 1.0.0
Finalidade: 00-Remessa regular de arquivo

Finalidade: 00-Remessa regular de arquivo
Hash do arquivo .txt:
93caedc97bc85dd17eff91c5804e307f30c31fb30fc1a58c6d4490499803519d
341a577ffd0709e89d1

Informações da Transmissão

Protocolo TED: 00009102
Data da transmissão: 22/02/2019 17:20:33

Informações do Processamento

Nº Identificador: 00055255
Data de processamento: 10/04/2019 22:46:28
Situação:

Informações do 4º Arquivo ______________________________

Referência: 08/2018
Nome do arquivo .txt: 44708379000999_201808.txt
Versão do leiaute: 1.0.0
Finalidade:
Hash do arquivo .txt:
2a4c2139ed297ac22c91b20d00a91dc8ae4f0f51789ca81690fa1dfd8c87a8ec
4a952ad80f1e7a35

Informações da Transmissão

Protocolo TED: 00009103
Data da transmissão: 22/02/2019 17:20:55

Informações do Processamento

Nº Identificador: 00055256
Data de processamento: 10/04/2019 22:46:37
Situação:

Informações do 5º Arquivo ______________________________

Referência: 09/2018
Nome do arquivo .txt: 44708379000999_201809.txt
Versão do leiaute: 1.0.0
Finalidade:
Hash do arquivo .txt:
9098e3fdfa25891b52fffce3073193e9af2802acb19a6441c35882dbcf4501ab
78289deb5d6f490844269

Informações da Transmissão

Protocolo TED: 00009104
Data da transmissão: 22/02/2019 17:21:08

Informações do Processamento

Nº Identificador: 00055257
Data de processamento: 10/04/2019 22:50:04
Situação:

Informações do 6º Arquivo ______________________________

Referência: 10/2018
Nome do arquivo .txt: 44708379000999_201810.txt

Finalidade: 00-Remessa regular de arquivo
Hash do arquivo .txt:
d85726faa39d7cc398223b008195d487d373cdfb90dee8395640573e2d2c2714
df9b17872f80046812e71c3f9e

Informações da Transmissão

Protocolo TED: 00009105
Data da transmissão: 22/02/2019 17:21:22

Informações do Processamento

Nº Identificador: 00055258
Data de processamento: 10/04/2019 22:50:13
Situação:

Informações do 7º Arquivo ______________________________

Referência: 11/2018
Nome do arquivo .txt: 44708379000999_201811.txt
Versão do leiaute: 1.0.0
Finalidade: 00-Remessa regular de arquivo

Finalidade: 00-Remessa regular de arquivo
Hash do arquivo .txt:
400aecce364e3c1f050aad2c2afd396c5ff82ef6a68d82f0cfa2e02b03b47f28
2fd321b3ee7f23c568b084

Informações da Transmissão

Protocolo TED: 00009106
Data da transmissão: 22/02/2019 17:21:35

Informações do Processamento

Nº Identificador: 00055259
Data de processamento: 10/04/2019 22:50:24

My Goal Result:
Exclude all words, but keep all terms “Referência:”

A list with:
[ Referência: 05/2018,
Referência: 06/2018,
Referência: 07/2018,
Referência: 08/2018,
Referência: 09/2018,
Referência: 10/2018,
Referência: 11/2018 ]

Gemini Test
If I ask to Gemini: Find all occurrences of the term “Referência:” in the text below and return the entire line of information or the next 8 charcters

Gemini results:

  • Store the text: The text you provided will be stored in a string variable.
  • Split the text: The code will break the text into individual lines. Iterate through the lines: It will go through each line of the text, one by one.
  • Check for occurrence: For each line, the program will check if the word “Referência:” is present. The check is performed in a way that doesn’t differentiate between uppercase and lowercase letters, ensuring that “referência:”, “REFERÊNCIA:”, or any variation is also found.
  • Print the result: If the keyword is found on a line, the program will print that entire line.
Ocorrências encontradas:
Referência: 05/2018
Referência: 06/2018
Referência: 07/2018
Referência: 08/2018
Referência: 09/2018
Referência: 10/2018
Referência: 11/2018

Question:

:light_bulb: What’s the best way to do it without using Python nodes (since I don’t have it installed on my computer)? or Java Snippet.

old school way is regex
another way is splitting the text at your keyword, and then extracting the first 8 characters from each element (but this is very inefficient in case you are faced with performance issues)

This should work. Uses Regex Extractor node. If you absolutely need a list use the entire workflow. If not, the Regex Extractor produces a data table.

3 Likes

That’s was perfect @rfeigel :heart_eyes:

“Regex Extractor” amazing node.

THANKSSSSSS

1 Like

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