Reputation: 11
I'm not sure this is even possible
I was given a requirement to match Purchase Order numbers within a filename. His requirement is below:
I would say a minimum of 4 characters, with no max limit. However there MUST be a string of 3 consecutive LETTERS (minimum) somewhere in this section.
123ABC - match A123ABC - match ABC123 - match 123XY67 - NO match ABC1VJ6K - match
The best I can come up with is [0-9A-Z]{4,}; however, that matches basically ANY 4 characters
Upvotes: 1
Views: 773
Reputation: 89557
you can use this pattern:
[A-Z0-9]*?[A-Z]{3}[A-Z0-9]+|[A-Z0-9]+?[A-Z]{3}[A-Z0-9]*
An other way with a lookahead:
(?=[A-Z0-9]*[A-Z]{3})[A-Z0-9]{4,}
And why not, if your regex engine allows conditional:
([A-Z0-9]+?)?[A-Z]{3}(?(1)|[A-Z0-9])[A-Z0-9]*
Upvotes: 2