From lines in a file i would like to find those that
^(202\d) for example 2022or 2023[A-Z]{1,4} or up to 3 numbers \d{1,3} and at least one letter [A-Z]{1} for example ABCD or A123 or 1A23 or 123AA or RExamples
YYYYxxxxA // find rows that match 2022xxxxA
2022A150A // relevant matches
2022B260A // "
20223A70A // "
20224B84A // "
20224B A // not relevant due to spaces \s\s
20221234A // not relevant due to 4 digits and no letter
In visual-studio-code i tested javascript regex (see my demo@regex101.com)
These two regex seem to work
2022(\d\D\w\w|\D\d\w\w|\d\d\D\w|\d\d\w\D|\D\D\D\D)A
// or
^(202\d)(\d{0,3}[A-Z]{1,4}|[A-Z]{1,4}\d{1,3})([\dA-Z]{0,4})A
202 literally and \d matches a digit (equivalent to [0-9])\d matches a digit (equivalent to [0-9]){0,3} matches the previous token between 0 and 3 times| are a variation of the firstI would like to know if there is a better option than
^(202\d)(\d{0,3}[A-Z]{1,4}|[A-Z]{1,4}\d{1,3})([\dA-Z]{0,4})A
for (xxxx) should contain at least 1 uppercase and no more than 3 digits?
Test with my demo
Your final regex will also match the below two lines, because it allows up to 3+4+4 characters for that second part, and also just 1 letter:
2022999BBBB9999A
2022BA
For the part that must have 4 alphanumericals, including at least one letter, you could express that condition as follows:
Like this: