I'm fiddling around with Java regex, and I'm trying to come up with a pattern that allows a certain set of characters anywhere else BUT it can't start with certain characters in the allowed set.
For example, let's say the allowed characters are from A to Z, but the string can't start with X or Z. How do I do that? I've come up with
You can use this regex:
^[A-WY]ensures that the first character is
[A-Z]*$will match 0 or more of any uppercase English letter
In general to exclude certain characters you can also use negative look-ahead:
(?![XZ]) is negative lookahead to disallow
Z at start.