Java – regular expressions match 17 uppercase characters
•
Java
In Java, which regex is more suitable for matching strings with a length of 17 characters? All strings are capitalized and do not include the letters I (I), O (o) or Q (q)
I've tried the following, but it still matches I, O and Q, even greater than or equal to 17
^[A-Z]+
How can I improve?
Solution
^(?!.*(?:[IOQ]))[A-Z]{17}$
^(?!.*(?:[IOQ]))[A-Z]{17}$
Just add a look ahead See demo
https://regex101.com/r/uF4oY4/24
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码