Regex Match capture repeated strings too (.txt file)

Hello everyone, :slight_smile:
First of all, I will make available here the .txt file I’m using: 12-03-2020 02_41_10_PM.txt (2.1 KB)

I am using a Regex to capture all item codes from a .txt file based on a specific pattern that these codes have. In the .txt file I uploaded here, this is the Item codes (BCU302, BSX2339568, BCU302). This is my regex:

System.Text.RegularExpressions.Regex.Match(myString, "[A-Z]{3}[0-9]{3} | [A-Z]{3}[0-9]{7} | [A-Z]{3}[0-9]{6} | [A-Z]{2}[0-9]{7} | [A-Z]{3}[0-9]{5}[A-Z]{1} | [A-Z]{2}[0-9]{6}[A-Z]{1}").Value

It works very well, but the only problem is when some item code is repeated in the .txt. When this happens, the Regex takes all the duplicates and counts as one. I would like to know if there is any way for my Regex to capture all the .txt codes, regardless of whether it is repeated or not.

Can somebody help me?

@req7
give a try on following for getting the count of all matches
System.Text.RegularExpressions.Regex.Matches (myString,
“[A-Z]{3}[0-9]{3} | [A-Z]{3}[0-9]{7} | [A-Z]{3}[0-9]{6} |
[A-Z]{2}[0-9]{7} | [A-Z]{3}[0-9]{5}[A-Z]{1} |
[A-Z]{2}[0-9]{6}[A-Z]{1}”).Count

Hey @ppr ! Thanks for the quick response!

I saw that this Regex counts the number of items that matches the specified pattern, but I would like to capture those items.
I want to capture all the items in the .txt, because then I will create an excel with those items.

If it helps, I’ll make my file available here: JN_CapturarDados.xaml (43.7 KB)
Here is the .txt from where I want to capture the items: 12-03-2020 02_41_10_PM.txt (2.1 KB)

@req7
dont missmatch match (single case) and matches (multiple cases)
have alook here fordemo purpose
req7.xaml (5.6 KB)

have a look on this activity

1 Like

Thank you so much!!! :grinning:

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