Using Regex OR operator to solve 2 conditions

asp.net, regex, vb.net

Solution

How about using `^[A-Z0-9]\d{8}$` ?

Problem

I am trying to combine 2 regular expressions into 1 with the OR operator: `|` I have one that checks for match of a letter followed by 8 digits: ``` Regex.IsMatch(s, "^[A-Z]\d{8}$") ``` I have another that checks for simply 9 digits: ``` Regex.IsMatch(s, "^\d{9}$") ``` Now, Instead of doing: ``` If Not Regex.IsMatch(s, "^[A-Z]\d{8}$") AndAlso Not Regex.IsMatch(s, "^\d{9}$") Then ... End If ``` I thought I could simply do: ``` If Not Regex.IsMatch(s, "^[A-Z]\d{8}|\d{9}$") Then ... End If ``` Apparently I am not combining the two correctly and apparently I am horrible at regular expressions. Any help would be much appreciated. And for those wondering, I did take a glance at How to combine 2 conditions and more in regex and I am still scratching my head.

Original source