I would like to integrate a total length check into the match, unfortunately I only succeed in the length match on the subgroups themselves.
Requirements: It should contain an alphanumeric string which contains letters from A-Z as well as numbers from 0-9 as well as 1 slash or 1 space but only in the middle, capturing is not needed.
^(?:[A-Z0-9]+(?:(?:-| )[A-Z0-9]+)?)$
^(?:[A-Z0-9]+(?:(?:-| )[A-Z0-9]+)?){1,11}$
>Solution :
Does the following do what you are after:
^(?!.{12})[A-Z0-9]+(?:[- ][A-Z0-9]+)?$
See an online demo. The use of the hyphen or space is now optional. Not sure if you want it compulsary, if so:
^(?!.{12})[A-Z0-9]+[- ][A-Z0-9]+$