I want a regex to select product references which fulfill these conditions:
- 8-character long
- starts with Q
- contains a mix of capital letters and numbers
- contains at least 1 number and 1 letter other than the initial Q
- ends with a letter or a number
For instance:
- QC1589ZH is valid ref
- Q1234567 is not a valid ref
- QUANTITY is not a valid ref
The regex will be used in a translation tool to select strings of text and block them. It will not be part of a code and thus cannot be tested or split. The software uses .NET regexes. I can use look-afters and look-behinds if it helps. The ref is always surrounded by spaces, line breaks, or at the begining or the end of a line.
Currently, I'm using the regex below. It works fine for valid refs but it also selects invalid refs like "Q1234567" and "QUANTITY".
\bQ[A-Z0-9]{7}\b
I have tried and modified several regexes suggested by others (notably here: Regex pattern to match at least 1 number and 1 character in a string) but they are all too greedy.