Regex capture similar strings in a .txt file

Hello there, :grinning:)

I’m using a Regex that captures strings in a .txt based on a specific pattern:

System.Text.RegularExpressions.Regex.Match(myString, “[AZ]{3}[0-9]{3}”).Value

The only problem with this Regex is that it does not capture data that are equal. For example, if the string XXX555 appears in the .txt, the Regex should capture that string, however, if the string XXX555 appears again, it should pick it up again.
This is not happening. It basically goes through the entire .txt, takes all occurrences that are the same and counts as if there were only one occurrence of the string XXX555.

I want to capture all occurrences of strings that match the pattern established in the Regex, no matter if they similar strings or not.

Somebody help me please

1 Like

Use System.Text.RegularExpressions.Regex.Matches(myString, "[A-Z]{3}[0-9]{3}") to get a collection of all matches in the txt file.


Thanks for the answer!
Should the variable that will receive this value be an array? Because my variable is a String type and is giving error:


The output will be a collection of matches as shown in your error (type System.Text.RegularExpressions.MatchCollection. A collection of matches is much like an array in that you can iterate over each match, and each match will have a Value property so you can get what was found.