I am looking for the most efficient way of finding matches in a string.

My attempt at a search expression is "\b[0-9]{4}[A-Z][0-9]{5}\b". But I am not sure how to deal with all the alternatives. I realize my search expression is for 2005Q99999.

So could someone help to get a search expression to match all these possible combinations. It would be great if it could be done in one search expression but I am not sure if that is possible.

The possible combinations I am looking for are below.

All numbers can be from 0-9 and all letters can be from A-Z.

200599999

2005Q99999

2005Q99999DJ

2005Q99999 TS (two blank spaces are in there)

2005Q99999 TS01 (two blank spaces are in there)

2005Q99999DJTS

2005Q99999DJTS01

05Q99999

05Q99999DJ

05Q99999 TS (two blank spaces are in there)

05Q99999 TS01 (two blank spaces are in there)

05Q99999DJTS

05Q99999DJTS01

*A little explanation:

Before the letter Q in my example there can only be 4 numbers or 2 numbers.

After the letter Q there can only be 5 numbers.

After the 5 numbers there are a number of alternatives

2 letters

2 spaces and 2 letters

2 spaces and 2 letters and 2 numbers

4 letters

4 letters and 2 numbers

Thanks for all your help people.

Open in new window