Add OR condition to a Regex

Hello everyone,

I’m using a regex to capture strings from a .txt file that have the first three values ​​as letters and the rest as numbers:

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

However, the .txt file from where I get these strings also has a pattern of 2 letters + numbers (example: BY4851) and 2 letters + numbers + letter at the end (example: BT47841X)

I would like to add an OR condition to the regex I already use, to add these two more conditions. Something like:

System.Text.RegularExpressions.Regex.Match (myString, “[AZ]{3}[0-9]{3}” || “[AZ]{2}[0-9]{4}” || "[ AZ]{2}[0-9]{5}[AZ]{1} ").Value

Somebody help me please :slight_smile:

Hi,

Can you try the following expression?

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

Regards,

1 Like

Thanks a lot!!! :slight_smile:

1 Like

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