String regex

Hello everyone!

I have a doubt about my regex expression.


NCC: / NSC: 140913;NSC: 141282;DOCUMENTO EMITIDO POR ME OU EPP OPTANTE PELO SIMPLES NACIONAL;; Voce pagou aproximadamente: R$ 4,24 de tributos federais R$ 11,22 de tributos estaduais Fonte: IBPT

(?<=((NSC):))(.+?)(?=([\ |])|([;|]))

In this case, he finds both NSCs, but cuts into the “;” How to make it capture both numbers and save in different variables?
It is correct to have only one NSC, but some cases appear two and are not always next to each other. Can anyone give me a tip

1 Like

The fastest way to do it is when you split your string with the “;” Seperator and assign it to the variables :slight_smile:

I thought about removing [; ] and putting some option to capture number only, but I haven’t found how to do that yet

1 Like

Kindly try with this expression
so that we will be getting all the matches
(?<=NSC:).+?(?=([\ |])|([;|]))

–which we can store or call by using FOR EACH loop and then pass the above obtained variable as input and change the type argument as System.Text.RegularExpressions.Regex.Match

Cheers @KMota

1 Like

Hi @Palaniyappan

(?<=((NSC):))(.+?)(?= ([\ |]) | ([\S;|])) With this correction the output was


I’m trying something like 140913;NSC:141282
or preferably

because then I could use split because the amount of numbers is always the same.

1 Like

here you go
hope its resolved (9.8 KB)

Cheers @KMota



I never used the proposed activity. I found it interesting, thanks again. You are the man

was using like this

1 Like

Cheers @KMota

1 Like

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