You must compare the string using a regular expression, for example:
str.matches("^[AZ]{2}\\d{4}") will give you a boolean as to whether it matches or not.
The regular expression works as follows:
^ Indicates that the following pattern needs to appear at the beginning of the string. [AZ] Indicates that the uppercase letters AZ are required. {2} Indicates that the preceding pattern is repeated twice (two AZ characters). \\d Indicates you expect a digit (0-9) {4} Indicates the the preceding pattern is expected four times (4 digits).
Using this method, you can scroll through any number of lines and check if they meet the specified criteria.
You should read regular expressions, but there are more efficient ways to store a pattern if you are worried about performance.
Ewald source share