'Validating an alphanumeric string having 8 or 11 chars and ending with a specific string [closed]

What would be regex for alphanumeric length is 8 or 11 and not end with XXX.

For example:

Invalid:

Ah7AyXXX
ahs221ssXXX
aed3

Valid:

Xg6tSSw3
ahs221sssws

In JavaScript, I tried with

(^[a-zA-Z0-9]{8}(XXX)$)|(^[a-zA-Z0-9]{11}$)

The pattern only matches some valid strings and also matches some invalid strings, you can see it in the regex demo:

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source