Regular expression : match either of two conditions?

In your regex, the two alternative branches are anchored separately: (^([a-zA-Z]){2}([0-9]){6}) – 2 letters and 6 digits at the start of the string | – or ([0-9]*)?$ – optional zero or more digits at the end of the string You need to adjust the boundaries of the group: See the regex demo. Now, the pattern will match: ^ – start … Read more